01 Binary Systems Part 1
01 Binary Systems Part 1
01 Binary Systems Part 1
1 0 1 0 1 1
25 24 23 22 21 20
= 1* 25 + 0 * 24 + 1 * 23 +0 * 22 + 1 * 21 + 1 *
20
= 32 + 8 + 2 + 1
= 43
Conversion from Binary to Decimal
26 / 2 = 13 Reminder 0
13 / 2 = 6 Reminder 1
6/2=3 Reminder 0
3/2=1 Reminder 1
1/2=0 Reminder 1 Leftmost (MSB: Most significant bit)
52 = (110100)2
Conversion from Decimal to Binary
(Cont.)
For fraction part employ iterative multiplication
Example: Convert (0.6875)10 to binary
0.6875 * 2 = 1.375 Integer 1
0.375 * 2 = 0.75 Integer 0
0.75 * 2 = 1.5 Integer 1
0.5 *2 =1 Integer 1
0.6875 = (0.1011)2
52.6875 = (110100.1011)2
How many bits are needed?
n bits can represent 2n unsigned integers from 0
to 2n - 1.
Example: What is the max number represented
by 12 bits?
212 can represent 4*1024 = 4096.
The max number that can be represented is 4095 =
(111111111111)2
Example: How many bits are needed to
represent 100 distinct numbers?
2x = 100
X = ceil(log2 100) = ceil(6.67) = 7 bits
Binary Arithmetic
0+0=0
0+1=1
1+0=1
1 + 1 = 10
1 + 1 + 1 = 11
Binary Arithmetic (Cont.)
Example: Add the two numbers 01111
(15) and 10111 (23).
1111 carry bits
01111
+
10111
100110
Check (100110)2 = 38
Binary Arithmetic (Cont.)
Example: Subtract the number 100111
from 101101.
11 borrow bits
101101
-
100111
000110
Binary Arithmetic (Cont.)
Example: Multiply 101 by 101.
101
* 101
101
+ 000
101
11001
Octal Numbering System
Octal number system is called base 8 or
radix 8 because:
Ituses 8 digits (0 to 7).
Each digit is multiplied by power of 8
according to its position.
Example: (127)8 = 1 * 82 + 2 * 81 + 7 * 80 =
(87)10
Conversion from Decimal to
Octal
Example: Convert (52)10 to octal
52 / 8 = 6 Reminder 4 Rightmost (LSB: Least significant bit)
6 / 8 = 0 Reminder 6 Leftmost (MSB: Most significant bit)
52 = (64)8
Conversion from Decimal to
Octal
Example: Convert (0.513)10 to octal
0.513 * 8 = 4.104 Integer 4
0.104 * 8 = 0.832 Integer 0
0.832 * 8 = 6.656 Integer 6
0.656 * 8 = 5.248 Integer 5
0.248 * 8 = 1.984 Integer 1
0.984 * 8 = 7.872 Integer 7
0.513 = (0.406517…)8
52.513 = (64.406517)8
Hexadecimal Numbering
System
Octal number system is called base 16 or
radix 16 because:
Ituses 16 digits (0 to 9, A, B, C, D, E, F).
Each digit is multiplied by power of 16
according to its position.
61 = (3D)16
Why Octal and Hexadecimal?
A big problem with the binary system is
the large number of bits used to represent
numbers. Octal and Hexadecimal are
more compact.
Example: The value (4095)10 can be
represented by 12 binary digits, or 3 Hexa
digits, or 4 Octal digits.
It's simple to convert them to binary and
vice versa.
Binary to Octal
23 = 8
To convert from binary to octal, partition
the number into groups of 3 bits, and
convert each group to its equivalent octal
digit.
Example: Convert 1011111010 to Octal
001 011 111 010
1 3 7 2
(1011111010)2 = (1372)8,
Octal to Binary
The reverse of the proceeding procedure,
each octal digit is converted to its
equivalent 3 bits.
Example: Convert (376)8 =to binary.
3 7 6
11 111 110
(376)8 = (11111110)2
Example
(10110001101011.1111001 )2
= (010 110 001 101 011 . 111 100 100)2
=( 2 6 1 5 3 . 7 4 4)8
= (26153.744)8
(673.124)8 = (110 111 011 . 001 010 100)2
= (110111011.0010101)2
Binary to Hexadecimal
24 = 16
To convert from binary to hexadecimal, partition
the number into groups of 4 bits, and convert
each group to its equivalent hexadecimal digit.
Example: Convert 1011111010 to hexadecimal
0010 1111 1010
2 F A
(1011111010)2 = (2FA)16
Hexadecimal to Binary
The reverse of the proceeding procedure,
each hexadecimal digit is converted to its
equivalent 4 bits.
Example: Convert (9C6)16 =to binary.
9 C 6
1001 1100 0110
(9C6)8 = (100111000110)16
Example
(10110001101011.1111001 )2
= (0010 1100 0110 1011 . 1111 0010)2
=( 2 C 6 B . F 2)16
= (2C6B.F2)16 = 2C6B.F2 H
= 0x 2C6B.F2
(306.D)16 = (0011 0000 0110 . 1101)2
= (1100000110.1101)2
Decimal Binary Octal Hexadecimal
0 0000 0 0
1 0001 1 1
2 0010 2 2
3 0011 3 3
4 0100 4 4
5 0101 5 5
6 0110 6 6
7 0111 7 7
8 1000 10 8
9 1001 11 9
10 1010 12 A
11 1011 13 B
12 1100 14 C
13 1101 15 D
14 1110 16 E
15 1111 17 F
Complement
Logic Operation : 0 ↔ 1
Arithmetic Operation : Subtraction
For base-r:
r’s complement
r-1’s complement
Diminished Radix (r-1)’s
Complement
Given a number N in base-r represented in
n digits, the (r-1)’s complement of N:
(rn -1) –N
For r=10 r-1 =9
9’s complements of N = (10n-1) – N
For r=2 r-1 =1
1’s complements of N = (2n-1) - N
Diminished Radix (r-1)’s
Complement Examples
The 9’s complement of 546700
r=10, n= 6, 106-1= 999999
9’s complements of 546700
= 999999 - 546700
= 453299
The 1’s complement of 1011000
r=2, n=7, 27-1= 1111111
1’s complements of 1011000
= 1111111 - 1011000
= 0100111
1’s Complement
1’s complement is formed by changing
every 1 to 0 and every 0 to 1
i.e.: Toggle each bit
Example: 1’s complement of 101100 is
010011
Diminished Radix r’s Complement