You are on page 1of 47

Number Systems

Module - 1

1
Numbers
• Each number system is associated with a base or radix
– The decimal number system is said to be of base or radix 10
• A number in base r contains r digits 0,1,2,...,r-1
– Decimal (Base 10): 0,1,2,3,4,5,6,7,8,9
• Numbers are usually expressed in positional notation

– MSD: most significant digit


– LSD: least significant digit 2
Numbers
• The value of the number is given in the polynomial form

3
Numbers

In addition to decimal, three other number systems are also


important: Binary, Octal, and Hexadecimal

4
Unsigned Binary Numbers
• The binary number system: Base-2
• Two digits: 0 and 1
• The digits in a binary number are called bits

– MSB: most significant bit


– LSB: least significant bit

5
Unsigned Binary Numbers

6
Unsigned Binary Numbers
• For a computer with the word size of 32-bit
- 4 data-bit unit – nibble (half byte)
- 8 data-bit unit - byte
- 16 data-bit unit – two bytes (half-word)
- 32 data-bit unit – word (four bytes)
- 64 data-bit unit – double-word

Powers of 2:
20 = 1 24 = 16 28 = 256
21 = 2 25 = 32 29 = 512
22 = 4 26 = 64 210 = 1024
23 = 8 27 = 128

210 : K (kilo); 220 : M (mega); 230 : G( giga )

7
Converting Binary to Decimal
• For example, here is 1101.01 in binary:
1 1 0 1 . 0 1 Bits
23 22 21 20 2-1 2-2 Weights (in base 10)

(1 x 23) + (1 x 22) + (0 x 21) + (1 x 20) + (0 x 2-1) + (1 x 2-2) =

8 + 4 + 0 + 1 + 0 + 0.25 = 13.25

(1101.01)2 = (13.25)10

8
Converting Decimal to Binary
• To convert a decimal integer into binary, keep dividing by 2 until
the quotient is 0. Collect the remainders in reverse order
• To convert a fraction, keep multiplying the fractional part by 2
until it becomes 0. Collect the integer parts in forward order
• Example: 162.375:
• So, (162.375)10 = (10100010.011)2

162 / 2 = 81 rem 0 0.375 x 2 = 0.750


81 / 2 = 40 rem 1 0.750 x 2 = 1.500
40 / 2 = 20 rem 0 0.500 x 2 = 1.000
20 / 2 = 10 rem 0
10 / 2 =5 rem 0
5/2 =2 rem 1
2/2 =1 rem 0
1/2 =0 rem 1
9
Why does this work?
• This works for converting from decimal to any base
• Why? Think about converting 162.375 from decimal to
decimal
162 / 10 = 16 rem 2 0.375 x 10 = 3.750
16 / 10 = 1 rem 6 0.750 x 10 = 7.500
1 / 10 = 0 rem 1 0.500 x 10 = 5.000
• Each division strips off the rightmost digit (the
remainder). The quotient represents the remaining
digits in the number
• Similarly, to convert fractions, each multiplication
strips off the leftmost digit (the integer part). The
fraction
represents the remaining digits

10
Decimal ‒to‒ Binary Conversion
The Process : Successive Division
a) Divide the Decimal Number by 2; the remainder is the LSB of Binary
Number .
b) If the quotation is zero, the conversion is complete; else repeat step (a)
using the quotation as the Decimal Number. The new remainder is the
next most significant bit of the Binary Number.

Example:
Convert the decimal number 610 into its binary equivalent.

3
2 6 r  0  Least Significan t Bit
1
2 3 r 1  610 = 1102
0
2 1 r  1  Most Significan t Bit
11
Dec → Binary : Example #1
Example:
Convert the decimal number 2610 into its binary equivalent.

12
Dec → Binary : Example #1
Example:
Convert the decimal number 2610 into its binary equivalent.

Solution:
13
2 26 r  0  LSB
6
2 13 r 1
3
2 6 r 0  2610 = 110102
1
2 3 r 1
0
2 1 r  1  MSB

13
Dec → Binary : Example #2
Example:
Convert the decimal number 4110 into its binary equivalent.

14
Dec → Binary : Example #2
Example:
Convert the decimal number 4110 into its binary equivalent.

Solution:
20
2 41 r  1  LSB
10
2 20 r 0
5
2 10 r 0  4110 = 1010012
2
2 5 r 1
1
2 2 r 0
0
2 1 r  1  MSB 15
Dec → Binary : More Examples

a) 1310 = ?

b) 2210 = ?

c) 4310 = ?

d) 15810 = ?

16
Dec → Binary : More Examples

a) 1310 = ? 11012

b) 2210 = ? 101102

c) 4310 = ? 1010112

d) 15810 = ? 100111102

17
Binary ‒to‒ Decimal Process
The Process : Weighted Multiplication
a) Multiply each bit of the Binary Number by it corresponding bit-
weighting factor (i.e. Bit-0→20=1; Bit-1→21=2; Bit-2→22=4; etc).
b) Sum up all the products in step (a) to get the Decimal Number.

Example:
Convert the decimal number 01102 into its decimal equivalent.

0 1 1 0
23 22 21 20
Bit-Weighting  0110 2 = 6 10
8 4 2 1 Factors

0 + 4 + 2 + 0 = 610

18
Binary → Dec : Example #1
Example:
Convert the binary number 100102 into its decimal equivalent.

19
Binary → Dec : Example #1
Example:
Convert the binary number 100102 into its decimal equivalent.

Solution:

1 0 0 1 0
24 23 22 21 20

16 8 4 2 1

16 + 0 + 0 + 2 + 0 = 1810

100102 = 1810

20
Binary → Dec : Example #2
Example:
Convert the binary number 01101012 into its decimal equivalent.

21
Binary → Dec : Example #2
Example:
Convert the binary number 01101012 into its decimal equivalent.

Solution:

0 1 1 0 1 0 1
26 25 24 23 22 21 20

64 32 16 8 4 2 1

0 + 32 + 16 + 0 + 4 + 0 + 1 = 5310

01101012 = 5310

22
Binary → Dec : More Examples

a) 0110 2 = ?

b) 11010 2 = ?

c) 0110101 2 = ?

d) 11010011 2 = ?

23
Binary → Dec : More Examples

a) 0110 2 = ? 6 10

b) 11010 2 = ? 26 10

c) 0110101 2 = ? 53 10

d) 11010011 2 = ? 211 10

24
Octal and Hexadecimal Numbers
• The octal number system: Base-8
• Eight digits: 0,1,2,3,4,5,6,7
(127.4)8  1 82  2  81  7  80  4  81  (87.5)10

• The hexadecimal number system: Base-16


• Sixteen digits: 0,1,2,3,4,5,6,7,8,9,A,B,C,D,E,F
• For our purposes, base-8 and base-16 are most
useful as a “shorthand” notation for binary
numbers 0
( B65F )16  1116  6 16  5 16  15 16  (46687)10
3 2 1

25
Numbers with Different Bases
Decimal Binary Octal Hex
0 0000 0 0
1 0001 1 1
2 0010 2 2 You can convert between base-10
3 0011 3 3 base-8 and base-16 using techniques
4 0100 4 4
like the ones we just showed for
5 0101 5 5
converting between decimal and
6 0110 6 6
binary
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
26
Binary and Octal Conversions
• Converting from octal to binary: Replace each octal digit with its
equivalent 3-bit binary sequence
(110111011.001010)2
(673.12)8 = 6 7 3 . 1 2
= 110 111 011 . 001 010
10110100.0010112 = = 010 110 100 . 001 0112
= 2 6 4 . 1 38

• Converting from binary to octal: Make groups of 3 bits, starting from the
binary point. Add 0s to the ends of the number if needed. Convert each bit
group to its corresponding octal digit.
Octal Binary Octal Binary
0 000 4 100
1 001 5 101
2 010 6 110
27
3 011 7 111
Binary and Hex Conversions
• Converting from hex to binary: Replace each hex digit with its
equivalent 4-bit binary sequence
261.3516 = 2 6 1 . 3 516
= 0010 0110 0001 . 0011 01012

• Converting from binary to hex: Make groups of 4 bits, starting from the
binary point. Add 0s to the ends of the number if needed. Convert each bit
group to its corresponding hex digit
10110100.0010112 = 1011 0100 . 0010 11002
= B 4 . 2 C16

Hex Binary Hex Binary Hex Binary Hex Binary


0 0000 4 0100 8 1000 C 1100
1 0001 5 0101 9 1001 D 1101
2 0010 6 0110 A 1010 E 1110
3 0011 7 0111 B 1011 F 1111
28
Number Systems Summary
• Computers are binary devices
– We’re forced to think in terms of base 2.
– We learned how to convert numbers between
binary, decimal, octal and hexadecimal
• We’ve already seen some of the recurring
themes of architecture:
– We use 0 and 1 as abstractions for analog voltages.
– We showed how to represent numbers using just
these two signals.

29
Binary Codes
• Decimal numbers are more natural to
humans. Binary numbers are natural to
computers.
• Binary codes are used in communication and
information systems
• Binary codes are used to represent letters,
numbers and punctuation marks.
• Binary codes are the basic building blocks of
modern digital computer techniques.
Types of Binary Codes
• BCD code
• Gray code
• Excess-3 code
• ASCII
• EBCDIC
The BCD Code
• BCD stands for Binary-Coded Decimal. The standard
binary code is used to convert decimal numbers into
equivalent binary numbers.
• A BCD number is a four-bit binary group that represents
one of the ten decimal digits 0 through 9.
Example:
Decimal number 4926 4 9 2 6

BCD coded number 0100 1001 0010 0110


Unsigned Binary Coded Decimal (BCD)

33
QUIZ

Convert the BCD coded number


1000 0111 0001 into decimal.

BCD Coded Number 1000 0111 0001

Decimal Number 8 7 1
QUIZ

Convert the decimal number


350 to its BCD equivalent.

Decimal Number 3 5 0

BCD Coded Number 0011 0101 0000


The Excess-3 Code
• Add 3 to each digit of decimal and
convert to 4-bit binary form
Decimal Binary +3 Excess-3
0 0000 0011 0011
1 0001 0011 0100
Sample Problem:
2 0010 0011 0101
3 0011 0011 0110
4 0100 0011 0111 Decimal 3 5 9
5 0101 0011 1000
6 0110 0011 1001
7 0111 0011 1010
8 1000 0011 1011 Excess-3 0110 1000 1100
9 1001 0011 1100
QUIZ

1. To form an excess-3 coded number,


decimal 3 is added to the decimal
number and this is converted to its 4-
bit binary code. (True or False) True

2. The excess-3 number 1010 0100 equals


__________ in decimal. 71

3. The decimal number 428 equals what


excess-3 number. 0111 0101 1011
The Gray Code
Decimal Gray code
• The Gray code’s most important 0 00000
characteristic is that only one 1 00001
2 00011
digit changes as you increment 3 00010
or decrement the count. 4 00110
5 00111
• The Gray code is also known as 6 00101
the mirror code. 7 00100
8 01100
9 01101
10 01111
11 01110
12 01010
13 01011
14 01001
15 01000
16 11000
QUIZ

1. The most important characteristic of


the ____________ (BCD, Gray code) Gray code
is that only one digit changes state as
you increment or decrement the
count.
2. The Gray code is also known as
mirror code (True or False)
True
Binary-to-Gray Code Conversion
 Retain most significant bit.
 From left to right, add each adjacent pair of binary code bits
to get the next Gray code bit, discarding carries.
 Example: Convert binary number 10110 to Gray code.
1 0 1 1 0 Binary 1 + 0 1 1 0 Binary 1 0 + 1 1 0 Binary
  
1 Gray 1 1 Gray 1 1 1 Gray

1 0 1 + 1 0 Binary 1 0 1 1 + 0 Binary
 
1 1 1 0 Gray 1 1 1 0 1 Gray

(10110)2 = (11101)Gray
Gray-to-Binary Conversion
 Retain most significant bit.
 From left to right, add each binary code bit generated to the
Gray code bit in the next position, discarding carries.
 Example: Convert Gray code 11011 to binary.

1 1 0 1 1 Gray 1 1 0 1 1 Gray 1 1 0 1 1 Gray


 +  + 
1 Binary 1 0 Binary 1 0 0 Binary

1 1 0 1 1 Gray 1 1 0 1 1 Gray
+  + 
1 0 0 1 Binary 1 0 0 1 0 Binary

(11011)Gray = (10010)2
The ASCII Code
• ASCII is an acronym for American Standard
Code for Information Interchange
• Represents numbers, letters, punctuation
marks and control characters
• Standard ASCII is a 7-bit code
• Extended ASCII (IBM ASCII), an 8-bit code, is
also very popular
• Extended ASCII adds graphics and math
symbols to code (total of 256 symbols)
QUIZ
1. A common 7-bit code used to represent
numbers, letters, punctuation marks,
and control characters is known by the
acronym __________. ASCII

2. The acronym ASCII stands for American Standard


__________________________. Code for Information
Interchange
3. Extended ASCII code is a(n)
__________ (8-bit, 10-bit) code 8-bit
which adds graphic and math
symbols to ASCII for a total of
256 symbols.
EBCDIC
• Extended Binary Coded Decimal
Interchange Code (EBCDIC) is an 8-bit
character encoding used mainly on IBM
mainframe and IBM midrange computer
operating systems.
• It employs 8 bits and hence we have a total of 256
combination of symbols
• We divide each combination of bits into two
groups. Each group in a combination contains 4
bits
Unicode
• An international character encoding standard
for use with different languages and scripts, by
which each letter, digit, or symbol is assigned
a unique numeric value that applies across
different platforms and programs.
Unicode
• Before Unicode was invented, there were
hundreds of different encoding systems for
assigning these numbers. No single encoding
could contain enough characters
• The latest version of Unicode contains a
repertoire of more than 128,000 characters
covering 135 modern and historic scripts, as
well as multiple symbol sets.

You might also like