Chapter 2 Number System and Codes
Chapter 2 Number System and Codes
• This shows that the overall structure of computers work only in binary conditions : :
2
Number Systems
• Basically, there are two types of number systems.
1. Non-positional number system:
• The symbols of the number have the same value regardless of its position in the
number.
• The value of a symbol (digit) in a number does not depend on the position of the
digit in number.
2. Positional number system:
• The value of a symbol in the number is determined by its position, the symbol and
the base of the number system.
• In all positional number systems, the base has the following properties:
3
… Cont’d
III. The positional value of each symbol is expressed by the power of the base.
4
Decimal Number System
• The decimal number system, also called the base 10 number system, is the number
system we use in our day-to-day life.
• The preference of this number system by humans is attributed to their nature that
humans have 10 fingers.
• It is believed that humans start counting using their fingers.
• This fact is the basis for the preference of the decimal number system by humans.
• The decimal number system has 10 different symbols identified as 0, 1, 2, 3, 4, 5, 6, 7,
8, and 9.
• All decimal numbers are written as a combination of these 10 digits.
• Example: number 83 means eight tens plus three:
83 = (8 * 10) + 3 5
… Cont’d
• The number 4728 means four thousands, seven hundreds, two tens, plus eight:
4728 = (4 * 1000) + (7 * 100) + (2 * 10) + 8
• The decimal system is said to have a base, or radix, of 10.
• This means that each digit in the number is multiplied by 10 raised to a power
corresponding to that digit’s position:
• The same principle holds for decimal fractions, but negative powers of 10 are used.
• Thus, the decimal fraction 0.256 stands for 2 tenths plus 5 hundredths plus 6
thousandths:
6
… Cont’d
• A number with both an integer and fractional part has digits raised to both positive and
negative powers of 10:
• In any number, the leftmost digit is referred to as the most significant digit, because it
carries the highest value.
• The rightmost digit is called the least significant digit.
• In the above example, the 4 on the left is the most significant digit and the 6 on the right
is the least significant digit.
• In general, for the decimal representation of X = {…d 2d1d0.d-1d-2d-3…}, the value of X is:
7
Binary Number System
• In the binary system, we have only two digits, 1 and 0.
• Thus, numbers in the binary system are represented to base 2.
• To avoid confusion, we will sometimes put a subscript on a number to indicate its base.
• For example, 8310 and 472810 are numbers represented in decimal notation or, more
briefly, decimal numbers.
• The digits 1 and 0 in binary notation have the same meaning as in decimal notation:
• Again, fractional values are represented with negative powers of the radix:
• In general, for the decimal representation of Y = {…b 2b1b0.b-1b-2b-3…}, the value of Y is:
8
Octal Number System
• Octal number system also called base 8 number system,
ↆ has 8 different symbols: 0, 1, 2, 3, 4, 5, 6, and 7.
• The octal number system is used to write binary numbers in short form.
• An octal umber has about one-third of the digits in its binary equivalent.
9
Hexadecimal Number System
10
Converting from one Base to Another Base
1. Conversion from Decimal to Base m
Step 1: Divide the given decimal number by m (the desired base).
• The result will have a quotient and a remainder.
Step 2: Divide the quotient by m.
• Still you get a quotient and a remainder.
Step 3: Repeat step 2 until the quotient becomes 0.
• You should note that we are conducting integer division.
• In integer division n/m, the quotient is 0 whenever n < m.
Step 4: Collect and arrange the remainders in such a way that the first remainder is the least
significant digit and the last remainder is the most significant digit (i.e., RnRn-1 … R2R1).
11
… Cont’d
• Example: Convert the following decimal number 47 into binary, octal, and hexadecimal.
a) Conversion to binary
• In order to convert the given decimal numbers into binary (base 2), they are divided by 2.
• Since the quotient becomes 0 at the last division, the division has to stop and we should
collect the remainders starting from the last one.
• Hence the result is 1011112.
• Note that, starting from the second division, at each consecutive division the quotient of
12
… Cont’d
b) Conversion to Octal
• Here the numbers are divided by 8 because the required base is octal (base 8).
c) Conversion to Hexadecimal
• Since the conversion now is into hexadecimal (base 16) the given decimal numbers are
divided by 16.
• It is evident that calculating the product of 0s since the product is 0 and do not contribute
anything to the final result.
• However, you should remember to skip the positional value as well.
14
… Cont’d
15
… Cont’d
• The bits are grouped in three with the equivalent octal digit given below
the three bit group.
• Thus, 1100112 = 638
• Since we are left with a single bit at the leftmost position, two
0s are added at the front to make create a three-bit group.
• The result shows that 11011112 = 1578.
16
… Cont’d
18
… Cont’d
Example 2: Find the octal equivalent for the hexadecimal number 3D5
Step 1: Convert 3D516 to binary
3 D 5
0011 1101 0101
Step 2: Convert 11110101012 to octal
001 111 010 101
1 7 2 5
Therefore, 3D516 = 17258
21
Integer Representation
• Integer can be represented as unsigned and signed
• Signed cane be classified into 3 such as :
1. Sign and magnitude
2. 1's complement
3. 2's complement
• Properties to follow for both unsigned and signed integers
Only one bit pattern per value
Equal number of positive and negative values
Maximum ranges of values
No gaps in the range
22
… Cont’d
A. Unsigned integer
Number of bits Range
• It is an integer without a sign.
8 0 - 255
• Its range is between 0 and positive infinity.
16 0 - 65,535
• Example 1: store 7 in an 8-bit memory location
Solution: first convert 7 in to binary which is 111
second add five 0’s to make total of N(8) bits which is
00000111
• Example 2: store 258 in an 16-bit memory location
Solution: first convert 258 in to binary which is 100000010
second add seven 0’s to make total of N(16) bits which is
0000000100000010
23
… Cont’d
24
… Cont’d
B. Signed integer
• Used to represent negative and positive integers.
i. Signed and Magnitude
• Left most significant bit represent the sign of the integers and the remaining bits
represent magnitude.
• If the leftmost bit is 0 the number is positive.
• And if the leftmost bit is 1 the number is negative.
• Example 1: store +7 in an 8-bit memory location using sign and magnitude.
Solution: 1) convert 7 in to binary which is 111
2) add four 0’s to make total of N-1(7)-bits which is
0000111
3) add an extra 0 because the number is positive.
So, the result is 00000111 25
… Cont’d
• Example 2: store -258 in an 16-bit memory location using sign and magnitude.
Solution: 1) convert 258 to binary which is 100000010
2) add six 0’s to make total of N-1(15)-bits which is 000000100000010
3) add an extra 1 because the number is negative.
So, the result is 1000000100000010
2. 1's complement
• The 1's complement of a number is found by changing all 1's to 0's and all 0's to 1’s.
• This is called as taking complement or 1's complement.
26
… Cont’d
3. 2's complement
• The 2's complement of binary number is obtained by adding 1 to the Least
Significant Bit (LSB) of 1's complement of the number.
2's complement = 1's complement + 1
• Example:
27
Fixed and floating point representation
1. Fixed Point Representation
• There is fixed number of digits after decimal part.
• Unsigned fixed point number
• Signed fixed point number
A. Unsigned fixed point number
• Example: Represent fixed point representation of unsigned binary number 0110.110
using 4 integer bits and 3 fractional bits.
• Solution: 0110.110
= 0*23+1*22+1*21+0*20+1*2-1+1*2-2+0*2-3
= 0+4+2+0+0.5+0.25+0
= (6.75)10
28
… Cont’d
= 64+32+16+8+4+2+1+0.5+0.25+0.125+0.0625
30
(011111111111) = (127.9375)
… Cont’d
2) (111111111111).
• solution: 111111111.1111 Integer part
Fraction part
-128 64 32 16 8 4 2 1 0.5 0.25 0.125 0.0625
1 1 1 1 1 1 1 1 1 1 1 1
= -128+64+32+16+8+4+2+1+0.5+0.25+0.125+0.0625
(111111111111)2 = (-0.0625)10
2) (000001110010). Integer part
Fraction part
solution: 00000111.0010
-128 64 32 16 8 4 2 1 0.5 0.25 0.125 0.0625
0 0 0 0 0 1 1 1 0 0 1 0
31
=4+2+1+0.125 = (7.125)
Floating Point Representation
• Binary point floats to the right of most significant 1 and an exponent is used.
• It can be represented in the scientific notation.
• It has three parts.
• Mantissa • Scientific Representation is ± mantissa * Base Exponent
• Base
• Exponent
• Example: number Mantissa Base Exponent
9*108 9 10 8
110*27 110 2 7
4346.254 4346254 10 -3
32
… Cont’d
(0.125)10 = (001)2
(1259.125)10 = (10011100011.001)2
Step 2: Normalize the number.
• formula to normalize in single precision is (1.N)2E-127
• formula to normalize in Double precision is (1.N)2E-1023
1.0011100011001*210
Step 3: Single Precision format
34
(1.N)2E-127 =
1.0011100011001*210
… Cont’d
• Numbers larger than 9, having 2 or more digits in decimal system are expressed digit by
digit. 1 8 9 5
0001 1000 1001 0101
• Example: BCD representation of base 10 numbers 1895 is
37
… Cont’d
38
… Cont’d
Alphanumeric codes
• Binary digit or bit can represent only two symbols as it has only two states '0' or '1’.
• But this is not enough for communication between two computers because there we
need many more symbols for communication.
• Alphanumeric codes consist of numbers as well as alphabetic characters.
• Commonly used Alphanumeric Codes:
1. ASCII - American Standard Code for Information Interchange
2. EBCDIC - Extended Binary Coded Decimal Interchange Code
• These codes contains: a) 26 alphabets with capital and small letters,
b) numbers (0 – 9)
c) punctuation marks and other symbols.
39
… Cont’d
End!!!
40