You are on page 1of 56

Information Representation

1
Decimal Numbers

2
Binary Numbers
Decimal Binary Number Decimal Binary Number
Number Number
0 0 0 0 0 8 1 0 0 0

1 0 0 0 1 9 1 0 0 1

2 0 0 1 0 10 1 0 1 0

3 0 0 1 1 11 1 0 1 1

4 0 1 0 0 12 1 1 0 0

5 0 1 0 1 13 1 1 0 1

6 0 1 1 0 14 1 1 1 0

7 0 1 1 1 15 1 1 1 1
3
Binary – to – Decimal Conversion
 Convert the binary whole number 1101 101 to
decimal

Weight : 26 25 24 23 22 21 20
Binary number: 1 1 0 1 1 0 1

1101101 = 26+25+24+23+22+21+20
= 64+32+8+4+1
= 109

4
Decimal – to – Binary Conversion
 Sum – of – Weight Method

Example : Decimal number 9 to binary

Solution :

9 = 8 + 1 or 9 = 2 + 2
3 0 23 22 21 20

1 0 0 1

5
Decimal – to – Binary Conversion
 Repeated Division – by – 2 Method
MSB – most
significant bit

LSB – least
significant bit

6
Binary Arithmetic
 Binary addition
 The four basic rules for adding binary digits
(bits) are as follows:

0+0=0 Sum of 0 with a carry of 0

0+1=1 Sum of 1 with a carry of 0

1+0=1 Sum of 1 with a carry of 0

1 + 1 = 10 Sum of 0 with a carry of 1

7
Binary Arithmetic
 Binary addition - Example

Carry bits

1 + 0 + 0 = 01 Sum of 1 with a carry of 0


1 + 1 + 0 = 10 Sum of 0 with a carry of 1
1 + 0 + 1 = 10 Sum of 0 with a carry of 1
1 + 1 + 1 = 11 Sum of 1 with a carry of 1

8
Binary Arithmetic
 Binary Subtraction
 The four basic rules for subtracting bits are as
follows:

Notes : In binary 10 – 1 = 1, not 9


0–0 =0

1–1 =0

1–0 =1

10 – 1 = 1 0 – 1 with a borrow of 1
9
Binary Arithmetic
 Binary Multiplication
 The four basic rules for multiplying bits are as
follows:

0x0=0
0x1=0
1x0=0
1x1=1

10
1’s Complement of Binary Numbers
 The 1’s complements is important because it
permits the representation of negative
numbers.
 The 1’s complement of a binary number is
found by changing all 1s to 0s and all 0s to 1s.

11
1’s Complement of Binary Numbers
 Application example
 Simplest way is to use parallel inverters.

12
2’s Complement of Binary Numbers
 Is found by adding1 to the LSB of the
1’s complement.

 2’s complement = (1’s complement) + 1

10110010 Binary number


01001101 1’s complement
+ 1 Add 1

01001110 2’s complement


13
2’s Complement of Binary Numbers
 Application Example

14
Signed Numbers
 Digital systems, such as the computers, must
be able to handle both positive and negative
numbers.
 A signed binary numbers consist of both sign
and magnitude information.
 The sign indicates whether a number is positive
or negative and the magnitude is the value of
the number.
 Three forms in which integer number can be
represented in binary.

15
Signed Numbers
 Sign Bit

 The left – most bit in a signed binary


number is the sign bit.
 0 is for positive
 1 is for negative

16
Signed Numbers
 Sign – Magnitude Form
 The left – most bit is the sign bit and the
remaining bits are the magnitude bits.
 Example : + 25 00011001

Sign bit Magnitude bits

 Example : - 25 10011001
Sign bit Magnitude bits

17
Signed Numbers
 1’s Complement Form

 Positive number represented the same way


as the positive sign – magnitude numbers.
 Negative number is the 1’s complement of
the corresponding positive number.

18
Signed Numbers
 2’s Complement Form

 Positive number represented the same way


as the positive sign – magnitude and 1’s
complement forms.
 Negative number is the 2’s complement of
the corresponding positive number.
(stopped here on 28 Dec 09)

19
Examples
1. Add the signed numbers: 01000100,
00011011, 00001110 and 00010010
2. Perform each of the following
subtractions of the signed numbers:
a) 10001000 - 11100010
b) 00001100 - 11110111
c) 00001000 - 00000011
d) 11100111 - 00010011
20
Examples
Arithmetic Operations with Signed Numbers
Using the signed number notation with negative
numbers in 2’s complement form simplifies addition
and subtraction of signed numbers.
Rules for addition: Add the two signed numbers. Discard
any final carries. The result is in signed form.
Examples:
00011110 = +30 00001110 = +14 11111111 = 1
00001111 = +15 11101111 = 17 11111000 = 8
00101101 = +45 11111101 = 3 1 11110111 = 9
Discard carry

21
Examples
Arithmetic Operations with Signed Numbers
Rules for subtraction: 2’s complement the subtrahend and
add the numbers. Discard any final carries. The result is in
signed form.
Repeat the examples done previously, but subtract:
00011110 (+30) 00001110 (+14) 11111111 (1)
 00001111 –(+15)  11101111 –(17)  11111000 –(8)
2’s complement subtrahend and add:
00011110 = +30 00001110 = +14 11111111 = 1
11110001 = 15 00010001 = +17 00001000 = 8
1 00001111 = +15 00011111 = +31 1 00000111 = +7
Discard carry Discard carry

22
Overflow
• happens when both numbers are positive
or both numbers are negative
• Example: 0111101 + 00111010 = ??
– needs 8 magnitude bits but only 7 magnitude
bits are available
– range from -128 to +127

23
Hexadecimal Numbers
 Has sixteen digits and is used primarily as a
compact way of displaying or writing binary
numbers because it is very easy to convert
between binary and hexadecimal.
 It is composed of sixteen digits and alphabetic
characters.
 The hexadecimal number system consist of
digits 0 – 9 and letters A – F.

24
Hexadecimal Numbers
Decimal Binary Hexadecimal Decimal Binary Hexadecimal

0 0000 0 8 1000 8
1 0001 1 9 1001 9
2 0010 2 10 1010 A
3 0011 3 11 1011 B
4 0100 4 12 1100 C
5 0101 5 13 1101 D
6 0110 6 14 1110 E
7 0111 7 15 1111 F

25
Binary – to – Hexadecimal
Conversion
 Simply break the binary number into 4 – bit
groups, starting the right – most bit and
replace each 4 – bit group with the equivalent
hexadecimal symbol.

 Example : 1100101001010111

1100 1010 0101 0111


C A 5 7

26
Hexadecimal – to – Binary
Conversion
 Reverse the process of Binary – to –
Hexadecimal and replace each hexadecimal
symbol with appropriate four bits.

 Example : 10A416

1 0 A 4
1 0000 1010 0100

27
Hexadecimal – to – decimal
Conversion (Method 1)
 Convert hexadecimal number to binary number first,
then convert from binary to decimal.

 Example : Convert 1C16 to decimal

Hexadecimal to binary: 1 C
0001 1100

Binary to decimal: 24 23 22 21 20
1 1 1 0 0

16+8+4=2810
28
Hexadecimal – to – decimal
Conversion (Method 1)
 Another way : multiply the decimal value of each
hexadecimal digit by its weight and then take the
sum of the products.

163 162 161 160


4096 256 16 1

 Example : E516 161 160 (E x 16) + (5x1)


E 5
= 224 + 5 = 22910

29
Decimal – to Hexadecimal
Conversion
 Repeated division of a decimal number by 16
 Example : 650 decimal to hexadecimal

30
Hexadecimal Addition
 Rules :
1. In any given column of an addition problem,
think of the two hexadecimal digits in term of
their decimal values. Example, 516 = 510 and
C16 = 1210
2. If the sum of these two digits is 15 10 or less,
bring down the corresponding hexadecimal
digit.
3. If the sum of these two digits is greater than
1510, bring down the amount of the sum that
exceeds 1610 and carry 1 to the next column.

31
Hexadecimal Addition
 Example :

2316 + 1616 = 3916

DF16 + AC16 = 18B16

Right column : F16 + C16 = 1510 + 1210 = 2710


DF16 2710 – 1610 = 1110 = B16 with a carry 1
+ AC16
Left column : D16 + A16 + 116= 1310 + 1010 + 110= 2410
2410 – 1610 = 810 = 816 with a carry 1

32
18B16
Hexadecimal (FF-2A= ??)

33
Examples
1. Convert B2F816 to decimal

2. 2B16 + 8416

3. 5816 + 2216

4. Convert FB0B16 to binary

5. 8416 – 2A16

6. C316 – 0B16
34
Octal Numbers
 Composed of eight digits which are
0, 1, 2, 3, 4, 5, 6, 7

 To count above 7, begin another column and


start over:
10, 11, 12, 13, 14, 15, 16, 17
20, 21, 22, 23, 24, 25, 26, 27

35
Octal – to – Decimal Conversion
 Example : 23748

Weight : 83 82 81 80
Octal number: 2 3 7 4

23748 = (2 x 83) + (3 x 82) + (7 x 81) + (4 x 80)


= (2 x 512) + (3 x 64) + (7 x 8) + (4 x 1)
= 1024 + 192 + 56 + 4
= 127610

36
Decimal – to – Octal Conversion

37
Octal – to – Binary Conversion

Octal Digit 0 1 2 3 4 5 6 7

Binary 000 001 010 011 100 101 110 111

 Example : 138 to binary (Answer : 001011)

1 3
001 011

38
Binary – to – Octal Conversion
 Reverse process of octal – to – binary
conversion.

 Example : 110101 (Answer = 658)

110 101
6 5

39
Gray Code
 Unweighted and is not an arithmetic code; that
is, there are no specific weights assigned to the
bit position.
 Important feature : it exhibits only a single bit
change from one code word to the next
sequence.

40
Examples
1. 1258 = 10

2. 7238 = 2

3. 9810 = 8

41
Gray Code
Decimal Binary Gray code Decimal Binary Gray code

0 0000 0000 8 1000 1100


1 0001 0001 9 1001 1101
2 0010 0011 10 1010 1111

3 0011 0010 11 1011 1110

4 0100 0110 12 1100 1010

5 0101 0111 13 1101 1011


6 0110 0101 14 1110 1001
7 0111 0100 15 1111 1000

42
Binary – to – Gray Code Conversion
Rules :
 The most significant bit (left – most) in the Gray code is
the same as the corresponding MSB in the binary
number.
 Going from left to right, add each adjacent pair of binary
code bits to get the next Gray code bit. Discard
carries.
 Example : 10110 to gray code. (11101)

43
Gray – to – Binary Conversion
Rules :
 The most significant bit (left – most) in the binary code
is the same as the corresponding bit in the Gray code.
 Add each binary code bit generated to the Gray code bit
in the next adjacent position. Discard carries.
 Example : gray code word 11011 to binary

44
Examples
1. Convert binary number 11000110 to
Gray code

2. Convert Gray code 10101111 to


binary

45
Decimal Binary BCD
BCD 0 0000 0000
1 0001 0001
Binary coded decimal (BCD) is a 2 0010 0010
weighted code that is commonly 3 0011 0011
used in digital systems when it is 4 0100 0100
5 0101 0101
necessary to show decimal 6 0110 0110
numbers such as in clock displays. 7 0111 0111
The table illustrates the 8 1000 1000
difference between straight binary and 9 1001 1001
BCD. BCD represents each decimal 10 1010
digit with a 4-bit code. Notice that the 11 1011
codes 1010 through 1111 are not used in 12 1100
BCD. 13 1101
14 1110
15 1111
46
Examples
Add the following BCD:

a) 0011 + 0100

b) 00100011 + 00010101

c) 1001 + 0100

47
ASCII
 Abbreviation for American Standard Code for
Information Interchange.
 Pronounced as ‘askee’.
 Universally accepted alphanumeric code used in the
most computers and other electronic equipments.
 Most computer keyboards are standardized with the
ASCII.
 Example : when enter a letter, number, or control
command, corresponding ASCII code goes into
computer.

48
ASCII
 Has 128 characters and symbols represented by a 7 –
bit binary code.
 It can be considered an 8 – bit code with MSB always 0.
 8 – bit code is 00 through 7F in hexadecimal.
 The first 32 ASCII characters are nongraphic commands
that are never printed on displayed and are used only for
control purposes.
 Example : null, line feed, start of text, and escape.
 The other characters are graphic symbols that can be
displayed and printed and include letters, numbers, ten
decimal digits, punctuation signs, and other commonly
used symbols.

49
1. For the binary number 1000, the weight of the column
with the 1 is
a. 4
b. 6
c. 8
d. 10

50
© 2008 Pearson Education
2. The 2’s complement of 1000 is
a. 0111
b. 1000
c. 1001
d. 1010

51
© 2008 Pearson Education
3. The fractional binary number 0.11 has a decimal value
of
a. ¼
b. ½
c. ¾
d. none of the above

52
© 2008 Pearson Education
4. The hexadecimal number 2C has a decimal equivalent
value of
a. 14
b. 44
c. 64
d. none of the above

53
© 2008 Pearson Education
5. The number 1010 in BCD is
a. equal to decimal eight
b. equal to decimal ten
c. equal to decimal twelve
d. invalid

54
© 2008 Pearson Education
6. An example of an unweighted code is
a. binary
b. decimal
c. BCD
d. Gray code

55
© 2008 Pearson Education
7. An example of an alphanumeric code is
a. hexadecimal
b. ASCII
c. BCD
d. CRC

56
© 2008 Pearson Education

You might also like