You are on page 1of 27

SEE 1223: Digital Electronics

1 Number Systems
Ab Al-Hadi Ab Rahman
Dept. of Microelectronics and Computer Engineering
The Faculty of Electrical Engineering
Universiti Teknologi Malaysia
Number Systems
Standard number systems
Decimal
Binary
Hexadecimal
Octal
Binary Codes
Binary Coded Decimal (BCD)
Gray Codes
ASCII
Representation of negative numbers
Sign magnitude
1s complement and 2s complement
Arithmetic operations using 2s complement
A.A.H Ab-Rahman January 2009 2
Binary Numbers
Counting in binary and decimal:
Binary Decimal
0000 => 0
0001 => 1
0010 => 2
0011 => 3
0100 => 4
0101 => 5 How to represent 16 in binary?
0110 => 6 => 100002
0111 => 7
1000 => 8 How to represent decimal 33?
1001 => 9 => 1000012
1010 => 10
1011 => 11 What is the value of 1001012
1100 => 12 => 37
1101 => 13
1110 => 14
1111 => 15
A.A.H Ab-Rahman January 2009 3
Binary Numbers (cont.)
Binary number system uses 0 and 1
Example: find the decimal value of 00101
Bit Position: 4 3 2 1 0

Binary: 0 0 1 0 1

Decimal: 0x24 0x23 1x22 0x21 1x20

0+ 0+ 4+ 0+ 1 =5

Therefore, 001012 = 510

A.A.H Ab-Rahman January 2009 4


Binary Numbers (cont.)
Convert these binary numbers to decimal:
10102 => 23 + 21 = 10
101112 => 24 + 22 + 21 + 20 = 23

Convert these decimal numbers to binary:


19 => 24 + 21 + 20 = 100112
58 => 25 + 24 + 23 + 21 = 1110102

A.A.H Ab-Rahman January 2009 5


Hexadecimal Numbers
Counting in hexadecimal
Binary Decimal Hexadecimal
0000 => 0 => 0
0001 => 1 => 1
0010 => 2 => 2
0011 => 3 => 3 How to represent 16 in hexadecimal?
0100 => 4 => 4 => 1016
0101 => 5 => 5
0110 => 6 => 6 Continue counting from 1016..
0111 => 7 => 7
1000 => 8 => 8 11, 12, 13, 14, 15, 16, 17, 18, 19, 1A
1001 => 9 => 9 1B, 1C, 1D, 1E, 1F, 20
1010 => 10 => A
1011 => 11 => B
1100 => 12 => C
1101 => 13 => D
1110 => 14 => E
1111 => 15 => F
A.A.H Ab-Rahman January 2009 6
Hexadecimal Numbers (cont.)
Hexadecimal number conversion: Convert
10110110110012 to hexadecimal
break binary into 4 groups
Binary: 1011011011001

1 6 D 9

Hexadecimal: 1 6 D 9 16

Can you convert this hex number to decimal?

=>1x163+6x162+13x161+9x160 = 584910

A.A.H Ab-Rahman January 2009 7


Hexadecimal Numbers (cont.)
Convert the following to binary:
CF8E16 => 1100 1111 1000 11102
97416 => 1001 0111 01002
Convert the following to hexadecimal
1111 0000 10102 => F0A16
10 0001 1101 10012 => 21D916

A.A.H Ab-Rahman January 2009 8


Octal Numbers
Counting in Octal
Binary Decimal Hexadecimal Octal
0000 => 0 => 0 => 0
0001 => 1 => 1 => 1
0010 => 2 => 2 => 2
0011 => 3 => 3 => 3
0100 => 4 => 4 => 4
0101 => 5 => 5 => 5
0110 => 6 => 6 => 6
0111 => 7 => 7 => 7 After 178?
1000 => 8 => 8 => 10
=> 208
1001 => 9 => 9 => 11
1010 => 10 => A => 12
1011 => 11 => B => 13
1100 => 12 => C => 14
1101 => 13 => D => 15
1110 => 14 => E => 16
1111 => 15 => F => 17
A.A.H Ab-Rahman January 2009 9
Octal Numbers (cont.)
Octal numbers conversion: Convert
1011111010001 to octal break binary into 3 groups

Binary: 1011111010001

1 3 7 2 1

Octal: 1 3 7 2 18

Can you convert this octal number to decimal?

=>1x84+3x83+7x82+2x81+1x80= 609710

A.A.H Ab-Rahman January 2009 10


Octal Numbers (cont.)
Convert the following to binary
258 => 10 1012
1408 => 001 100 0002
Convert the following to octal
110 1012 => 658
1 101 111 0012 => 15718

A.A.H Ab-Rahman January 2009 11


More Number Conversions
Convert A7B16 to binary and decimal easy
Convert 65010 to hexadecimal 2 ways
Convert to binary first, then to hex
Convert directly to hex

A.A.H Ab-Rahman January 2009 12


More number conversions (cont.)
65010 to binary using repeated division method:
650/2 = 325, remainder 0 Least significant bit (MSB)
325/2 = 162, remainder 1
162/2 = 81, remainder 0
81/2 = 40, remainder 1
40/2 = 20, remainder 0
20/2 = 10, remainder 0
10/2 = 5, remainder 0
5/2 = 2, remainder 1
2/2 = 1, remainder 0
1/2 = 0, remainder 1 Most significant bit (MSB)

Therefore, 65010 = 10100010102


What is 65010 in hexadecimal? 65010 = 28A16

A.A.H Ab-Rahman January 2009 13


More number conversions (cont.)
65010 to hexadecimal using repeated division method:

650/16 = 40.625 0.625 x 16 = 10 A Least significant bit (MSB)

40/16 = 2.5 0.5 x 16 = 8 8

2/16 = 0.125 0.125 x 16 = 2 2 Most significant bit (MSB)

Therefore, 65010 = 28A16

A.A.H Ab-Rahman January 2009 14


Fractional Numbers
Fractional numbers in binary

Bit Position: 3 2 1 0 . -1 -2 -3 -4

Binary: 1 0 0 1 .1 0 1 1

Decimal point

Therefore, the above binary in decimal:


=> 23 + 20 + 2-1 + 2-3 + 2-4 = 9.6875

A.A.H Ab-Rahman January 2009 15


Fractional Numbers (cont.)
Fractional numbers in hexadecimal

Binary: 1 1 0 0 1 .1 0 1 1 1

1 9 B 8

Therefore, the above binary in hexadecimal:


=> 19.B816

A.A.H Ab-Rahman January 2009 16


Fractional Numbers (cont.)
Fractional numbers in octal

Binary: 1 1 0 0 1 .1 0 1 1 1

3 1 5 6

Therefore, the above binary in octal:


=> 31.568

A.A.H Ab-Rahman January 2009 17


Fractional number conversion
Convert A7B.9116 to binary and decimal easy
Convert 650.7510 to hexadecimal 2 ways
Convert to binary first, then to hex
Convert directly to hex

A.A.H Ab-Rahman January 2009 18


Fractional number conversion
Convert 650.37510 to binary using repeated
division and multiplication
We have seen that 65010 = 10100010102 (Using repeated division)

Need to find 0.37510 in binary: Use repeated multiplication

0.375 x 2 = 0.75 0

0.75 x 2 = 1.5 1
No more fractional number, stop multiply
0.5 x 2 = 1 1

Therefore, 0.37510 = 0.011

Therefore, 650.37510 = 1010001010.011


A.A.H Ab-Rahman January 2009 19
Fractional number conversion
Convert 650.37510 to hexadecimal using repeated
division and multiplication
We have seen that 65010 = 28A16 (Using repeated division)

Need to find 0.37510 in hexadecimal: Use repeated multiplication

0.375 x 16 = 6 6
No more fractional number, stop multiplication

Therefore, 0.37510 = 0.616

Therefore, 650.37510 = 28A.616

A.A.H Ab-Rahman January 2009 20


Binary Coded Decimal (BCD)
Each decimal digit (0 to 9) is represented by 4
bit binary
Binary Decimal
0000 => 0
0001 => 1 How to represent 28 in BCD?
0010 => 2 => 0010 10002
0011 => 3
0100 => 4 What is 0011 0010 in BCD?
0101 => 5 => 32
0110 => 6
0111 => 7 What is 32 in binary?
1000 => 8 => 1000002
1001 => 9

A.A.H Ab-Rahman January 2009 21


Gray Code
Binary Decimal Gray Code
0000 => 0 => 0000
0001 => 1 => 0001
0010 => 2 => 0011
0011 => 3 => 0010
0100 => 4 => 0110 Exhibits a single
0101 => 5 => 0111
0110 => 6 => 0101
bit change from
0111
1000
=>
=>
7
8
=>
=>
0100
1100
one code word
1001 => 9 => 1101 to another
1010 => 10 => 1111
1011 => 11 => 1110
1100 => 12 => 1010
1101 => 13 => 1011
1110 => 14 => 1001
1111 => 15 => 1000
A.A.H Ab-Rahman January 2009 22
Binary-Gray Code Conversions
MSB of Gray Code is the same MSB in binary
From left to right, add each adjacent pair of
binary code, discard carry

Binary: 1 + 0 + 1 + 1 + 0 => 22

Gray Code: 1 1 1 0 1

Therefore, binary 10110 is equivalent to gray code 11101

A.A.H Ab-Rahman January 2009 23


Gray Code-Binary Conversions
MSB of binary is the same MSB in Gray Code
From left to right, add each generated binary
code with adjacent Gray Code, discard carry

Gray Code: 1 1 0 1 1
+ + + +

Binary: 1 0 0 1 0 => 18

Therefore, gray code11011 is equivalent to binary 10010

A.A.H Ab-Rahman January 2009 24


ASCII
American Standard Code for Information
Interchange
128 characters, represented by 8-bit binary
code with MSB 0
The 8-bit code runs from 0016 to 7F16
The first 32 ASCII characters used for controls
such as ESC, new line, space, start of text, etc
Other characters include letters (upper and
lower case), decimal digits, and symbols
A.A.H Ab-Rahman January 2009 25
ASCII Table

A.A.H Ab-Rahman January 2009 26


ASCII Example
Find the ASCII equivalent ab.12 in binary
=> 0110 0001 0110 0010 0010 1110 0011 0001 0011 0010

A receiver receives the bit sequence:


504D544B2316
Find the ASCII characters corresponding the
transmitted data
=> PMTK#

A.A.H Ab-Rahman January 2009 27

You might also like