02 Number Systems (1)
02 Number Systems (1)
Number Systems
By
Darshit Shah
PDEU, Gandhinagar
BIT
Bit is abbreviation of ‘Binary Digit’.
The smallest Unit in the Computer.
It can store either 0 or 1 but not both
simultaneously.
i.e. they are mutually exclusive.
In computer terminology, 1 means on
and 0 means off.
BIT
No. of Different No. of Different Highest Value stored
Combinations
Bits Combinations
= 2No.of Bits = 2No.of Bits – 1
1 0 1 21 = 2 21-1 = 1
00 01
2
10 11 22 = 4 22-1 = 3
000 001
010 011
3
100 101 23 = 8 23-1 = 7
110 111
Byte
The smallest unit inside the computer is
bit.
However, a single bit can’t be used to
store different numbers, alphabets or
special symbols.
So we require a series of bits.
8 bits together makes one byte.
With one byte, we can store 256
different combinations, which include
digits, alphabets and special symbols.
BIT-> Tera Byte
Relationship
8 BITS = 1 byte
4 BITS = 1 Nibble
1 Byte = 2 Nibbles
1024 Bytes = 1 Kilo Byte (KB)
1024 KB = 1 Mega Byte (MB)
1024 MB = 1 Giga Byte (GB)
1024 GB = 1 Tera Byte (TB)
or (100 + 50 + 3 + .2 + .05)
Binary Number System
Radix or Base 2
Digits 0&1
Conversion To Decimal
(1101.11)2 = (1 * 23) + (1 * 22) + (0 *
21) + (1 * 20) + (1 * 2-1)
+ ( 1 * 2-2)
= (8 + 4 + 0 + 1 + .5 + .25 )
= (13.75)10
Binary Number System
Radix or Base 2
Digits 0&1
Binary to Decimal Conversion
(1101.11)2 23= 22 21 20 . 2-1 2-2
8 4 2 1 . 0.50 0.25
1 1 0 1 . 1 1
8 4 0 1 . 0.50 0.25
= (13.75)10
Octal Number System
Radix or Base 8 (23 )
Digits 0–7
Conversion To Decimal
(250.14)8 = (2 * 82) + (5 * 81) + (0
* 80) + (1 * 8-1) + ( 4
* 8-2)
= (128 + 40 +0+0.125 +
0.0625 )
Hexadecimal Number System
Radix or Base 16 (24 )
Digits 0 – 9,10->A.,15->F
Conversion To Decimal
(AB.75)16 =(A*161)+(B*160)+(7*16-1)
+(5*16-2)
=
(10*16)+(11*1)+(7/16)+(5/256)
= (171.45703125)10
Decimal->Binary Conversion
(35.25)10 = (?)2
(35.25)10 = (43.2)8
Decimal->HexaDecimal
Conversion
16 35
.25
16 2 3
* 16
0 2
--------
.00 4
(35.25)10 = (23.4)16
Conversion: BinaryOctal
Two Ways
Convert Binary To Decimal;
And Decimal To Octal
Or
Or
(AC0E)16 = ( ? )8 ( ? )10 ( ? )2
(182.75)10 = ( ? )2 ( ? )16 ( ? )8
ASCII
American Standard Code For Information
Interchange
1 = 1111 0001
5 = 1111 0101
3 = 1111 0011
= (11110001 11110101
11110011) EBCDIC
2’s Complement Method
Most common number code for
storing integer values inside the
computer.
It can store signed as well as
unsigned numbers.
The signs of all bits except the left
most bit are
- ++ve
+ and
+ + the sign of
leftmost bit is –ve.
Drawback of 1's Complement
Method
Suppose we have only 2 bits and we want to
store –ve numbers also, we will have to take
one bit for storing sign. 0 means number is
+ve and 1 means number -ve.
Sign bit Digit Bit
0 0 = +0
0 1 = +1
1 0 = -0
1 1 = -1
The Range will be -1 to +1 as there are two
representations of zero.
Drawback of 1's Complement
Method
Suppose we have only 3 bits and we want to
store –ve numbers also, we will have to take
one bit for storing sign. 0 means number is
+ve and 1 means number -ve.
Sign bit Digit Bit Digit bit
0 0 0 = +0
0 1 1 = +3
1 0 0 = -0
1 1 1 = -3
The Range will be -3 to +3 as there are two
representations of zero.
2’s Complement Method
0 0 0 = 0
0 1 1 = 3
1 0 0 = -4
2’s Complement Method
The Range of Numbers
-(2(no.of bits-1)) to +2(no.of bits-1) -1
With 3 BITS : -4 to +3
With 4 BITS : -8 to +7
With 8 BITS : -128 to
+127
With 16 BITS : -32768 to
+32767
Here, only left most bit will have –ve
weight.
2’s Complement Method
Convert decimal to 2’s complemented
form (using 8 bits)
107
-107
Convert following 2’s complement
numbers into decimal. (Using 8 bits)
10001101
01111111
Binary Arithmetic-Addition
0 + 0 = 0
0 + 1 = 1
1 + 0 = 1
1 + 1 = 0 with carry 1. (1 0)
Therefore, 1 + 1 + 1 = 1 with carry 1
TRY THESE:
10001001 10110 11
+1 0 0 1 1 0 1 1 +1110001
100100100 110011
00
Logic Circuits
Basic logic Gates: AND, OR, NOT
A A
AND OR A NOT
B B
A A A
0 1 0 1 0 1
0 0 0 0 0 1 1 0
B B
1 0 1 1 1 1
Logic Circuits
Basic logic Gates: AND, OR, NOT
A A
AND OR A NOT
B B
A A A
Fals Tru Fals Tru
e e e e False
B Fals Fals Fals B Fals Fals True True
e e e e e
True Fals
e
True True True True True
False
Circuit for Addition
A OR
AND S
B AND NOT
A
AND C
B
A OR
AND S
B AND NOT
S
A+B A OR A AND NOT (4)
A B
(3) B (4) B (5) (6) and
(5)
0 0 0 0 0 1 0
0 1 1 1 0 1 1
1 0 1 1 0 1 1
0
1 1 with 1 1 0 0
carry 1
Results of A + B (3) and S are same, means circuit is
correct.
Binary Arithmetic-Multiplication
Binary Equivalent decimal
multiplication multiplication
5
0101 A ×11
× 1011 B 55
0101
0101 Shift A left to multiply by B1 (= 21)
0000 Since B2 = 0
0101
0110111
• Manual verification: 32 + 16 + 4 + 2 + 1 = 55
• Implemented in hardware using multiple
shift-left and add steps
Binary Arithmetic-Subtraction
(10101) – (1010) = ( ? ) 2
2 2
C
1 0 1 0 1 ----> 0 1 0 1 0
- 0 1 0 1 0 -----> + 0 1 0 1 0
C
1 0 1 0 0 ----> 0
1 0 1 1
Floating Point Representation
Numbers having an Integer part
and a Fractional part, is called a
Real Number or Floating-Point
Number.
It can be either +ve or –ve.
Every number can be represented
in a Scientific Form i.e. N = m r
e
Floating Point Representation
mantissa & exponent can be
+ve or –ve
3.1415 = .31415 x 101
3141.5 = .31415 x 104
0.0031415 = .31415 x 10-2
-31.415 = -.31415 x 102
Note that
.31415 = (3 x 10-1) + (1 x 10-2) + (4 x
10-3) +
(1 x 10-4) + (5 x 10-5)
Binary Floating Point
Representation
IEEE 754 Floating Point Standards
31 30………….23 22………………………0
sign exponent mantissa
Example
(−118.625) = ( ? )32-BITS IEEE FORMAT
10
31 30 23 22 0
1 10000101 11011010100000000000000
Binary Floating Point
Representation
IEEE 754 Floating Point Standards
Double Precision (64 Bits)
1 Bit To Store Sign (Left Most Bit)
Exponent Uses 11 Bits “Biased”
Representation
“Biased” Mean Adding 1023 To Exponent
Exponent Ranges From -1022 To +1023
52 Bits For Mantissa
63 62………….52 51………………………0
sign exponent mantissa
What To Use? When?
Trade-off between the range of numbers
and accuracy.
If we increase the exponent bits in 32-
bit format, the range can be increased
but accuracy of number goes down as
size of mantissa will become smaller.
Higher the no. of bits in mantissa,
better will be precision.
What To Use? When?
For increasing both precision and
range, use double precision.
in C/C++
use float data type for single precision.
use double data type for double
precision.
Arithmetic on Real Nos.
Arithmetic on real numbers are more
complicated.
Most ALU do only integer arithmetic
Real (floating point) arithmetic is done
in software on some low-end processors.
in a floating-point unit (FPU) on most
modern processors.
Most processors today support single
and double precision floating point
arithmetic. 02