Location via proxy:   [ UP ]  
[Report a bug]   [Manage cookies]                
0% found this document useful (0 votes)
10 views

02 - Binary Systems - 1

Uploaded by

philopateer
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
10 views

02 - Binary Systems - 1

Uploaded by

philopateer
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 46

Binary Systems

The credit of these slides belong to:


Prof. Dr. Hazem Abbas

Computer and Systems Engineering


Department
1
Outline
1. Digital Systems
2. Binary Numbers
3. Number Base Conversions
4. Octal and Hexadecimal Numbers
5. Complements
6. Signed Binary Numbers
7. Binary Codes
8. Binary Logic

2
Analog Vs Digital Signals
◼ Analog signals are continuous electrical
signals that vary in time.

3
Analog Vs Digital Signals
◼ Digital signals are non-continuous, they change
in individual steps. They consist of pulses or
digits with discrete levels or values.
◼ Binary System manipulates discrete data
represented in binary form.
◼ Described by a signal of two amplitude levels
called 1 or 0, HIGH or LOW, TRUE or FALSE,
On or OFF.

5
Binary Digital System
▪ A Binary digit is called a bit.
▪ A Bit has one of two possible values (0 or 1).
▪ A Byte is an 8-bit chunk (1 Byte = 8 bits)
▪ 1 Kilobyte (KB) = 210 bytes = 1,024 bytes
▪ 1 Megabyte (MB) = 220 bytes = 1,048,576 bytes
▪ 1 Gigabyte (GB) = 230 bytes = 1,073,741,824
bytes
▪ Terabyte (TB) = 240 bytes = 1,099,511,627,776
bytes

6
Computer is a
Binary System

7
Decimal Numbering System
◼ A digit is either 0, 1, 2, ….. Or 9 (10 digits)
◼ Example: Decimal number 9457

9 4 5 7

Thousands Hundreds Tens Units


103 102 101 100
9 thousands + 4 hundreds + 5 tens + 7 units
= 9 * 103 + 4 * 102 + 5 * 101 + 7 * 100
= 9457

8
Decimal Numbering System (Cont.)

◼ Example: Decimal number 38.24


3 8 . 2 4

101 100 10-1 10-2

3 * 101 + 8 * 100 + 2 * 10-1 + 4 *


10-2
Power of 10 = Digit Position = 30 + 8 + 0.2 + 0.04
= 38.24

9
Decimal Numbering System (Cont.)

◼ Decimal number system is called base 10


or radix 10 because:
 Ituses 10 digits (0 to 9).
 Each digit is multiplied by power of 10
according to its position.

10
Binary Numbering System
◼ Decimal number system is called base 2
or radix 2 because:
 Ituses 2 digits (0 or 1).
 Each digit is multiplied by power of 2
according to its position.

Remember: A binary digit is called a bit.

11
Binary Numbering System
(Cont.)
◼ Example: binary number (101011)2

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 12
Conversion from Binary to Decimal

◼ To convert from binary to decimal add the


numbers with power of two corresponding
to the bits that are equal to 1.
Example: Convert (110100)2 to decimal
(110100)2 = 1*25 + 1*24 + 1*22
= 32 + 16 + 4 = (52)10

13
Conversion from Binary to Decimal

Example: Convert (11010.11)2 to decimal


(11010.11)2
= 1*24 + 1*23 + 1*21 + 1*2-1 +1*2-2
= 16 + 8 + 2 + 0.5 + 0.25 = (26.75)10

14
Conversion from Decimal to Binary

◼ To convert from decimal to binary:


 Divide the number by two. The remainder
(either 0 or 1) is the rightmost binary digit.
 Divide the quotient by two. This remainder will
be the next binary digit to the left.
 Continue dividing the successive quotients by
two and using the remainder as the next
binary digit to the left, and
 stop when the quotient is finally zero.
15
Conversion from Decimal to Binary
(Cont.)
Example: Convert (52)10 to binary
52 / 2 = 26 Remainder 0 Rightmost (LSB: Least significant bit)

26 / 2 = 13 Remainder 0
13 / 2 = 6 Remainder 1
6/2=3 Remainder 0
3/2=1 Remainder 1
1/2=0 Remainder 1 Leftmost (MSB: Most significant bit)

52 = (110100)2
16
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
17
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

19
Binary Arithmetic
◼ 0+0=0
◼0+1=1
◼1+0=1
◼ 1 + 1 = 10
◼ 1 + 1 + 1 = 11

20
Binary Arithmetic (Cont.)
◼ Example: Add the two numbers 01111
(15) and 10111 (23).
1111  carry bits
01111
+
10111
100110
◼ Check (100110)2 = 38

21
Binary Arithmetic (Cont.)
◼ Example: Subtract the number 100111
from 101101.
11  borrow bits
101101
-
100111
000110

22
Binary Arithmetic (Cont.)
◼ Example: Multiply 101 by 101.
101
* 101

101
+ 000
101
11001
23
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

24
Conversion from Decimal to
Octal
Example: Convert (52)10 to octal
52 / 8 = 6 Remainder 4 Rightmost (LSB: Least significant bit)
6 / 8 = 0 Remainder 6 Leftmost (MSB: Most significant bit)

52 = (64)8

25
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
26
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.

Example: (B65F)16 = (B65F)H = 11 * 163 + 6 *


162 + 5 * 161 + 15 * 160 = (46687)10

27
Conversion from Decimal to
Hexadecimal
Example: Convert (61)10 to hexadecimal
61 / 16 = 3 Remainder 13=D
3 / 16 = 0 Remainder 3

61 = (3D)16

28
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.
29
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,
30
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

31
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

32
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

33
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

34
Example
◼ (0010 1100 0110 1011.1111 0010 )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

35
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 36
Complement
◼ Logic Operation : 0 ↔ 1
◼ Arithmetic Operation : Subtraction

◼ For base-r:
 r’s complement
 (r-1)’s complement

37
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

38
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

39
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

40
Diminished Radix r’s Complement

◼ Given a number N in base-r represented in n


digits, the r’s complement of N:
rn – N
(r-1)’s complement + 1
◼ For r=10
 10’s complements of N = (10n) – N
◼ For r=2
 2’s complements of N = (2n) - N

41
Diminished Radix r’s Complement
Examples
◼ The 10’s complement of 546700
 r=10, n= 6, → 106 = 1000000
 10’s complements of 546700
= 1000000 - 546700
= 453299 + 1
= 453300
◼ The 2’s complement of 1011000
 r=2, n=7, → 27 = 10000000
 1’s complements of 1011000
= 10000000 - 1011000
= 0100111 + 1
= 0101000

42
2’s Complement
◼ 2’s complement is formed by leaving all
least significant 0’s and first 1 unchanged
and inverting all others.
Example: 2’s complement of 101100 is
010100

43
Signed Binary Numbers
◼ A sign bit at the leftmost position of the
number is added.
◼ The sign bit is 0 for positive and 1 for
negative.
◼ Example: Representing 9 and -9 using 8
bits:
9 : 0 0001001
 -9 : 1 0001001

Sign bit value 44


Different representation of –ve
values
◼ Presentation formats of value -9
 Signed-magnitude 10001001
 Signed 1’s complement 11110110
 Signed 2’s complement 11110111

45
Readings
◼ Mano & Kime, Chapter 1

46

You might also like