MMNSS COLLEGE,KOTTIYAM DEPARTMENT OF PHYSICS DIGITAL ELECTRONICS
Digital devices are based on electronic circuitry It represents two states 1 or high & 0 or low In this system, terms like bit, nibble & byte are frequently used
NUMBER SYSTEMS
Objectives After studying this chapter, You should be able to: Understand the concept of number systems. Distinguish between non-positional and positional number systems. Describe the decimal, binary, hexadecimal and octal system. Convert a number in binary, octal or hexadecimal to a number in the decimal system. Convert a number in the decimal system to a number in binary, octal and hexadecimal. Convert a number in binary to octal and vice versa. Convert a number in binary to hexadecimal and vice versa. Find the number of digits needed in each system to represent a particular value.
2-1 INTRODUCTION A number system defines how a number can be represented using distinct symbols. A number can be represented differently in different systems. For example, the two numbers (2A)16 and (52)8 both refer to the same quantity, (42)10, but their representations are different. Several number systems have been used in the past and can be categorized into two groups: positional and non-positional systems. Our main goal is to discuss the positional number systems, but we also give examples of non-positional systems.
Common Number Systems System Base Symbols Used by humans? Used in computers? Decimal 10 0, 1, … 9 Yes No Binary 2 0, 1 Octal 8 0, 1, … 7 Hexa- decimal 16 0, 1, … 9, A, B, … F
Quantities/Counting (1 of 3) Decimal Binary Octal Hexa- decimal 1 2 10 3 11 4 100 5 101 6 110 7 111
Quantities/Counting (2 of 3) Decimal Binary Octal Hexa- decimal 8 1000 10 9 1001 11 1010 12 A 1011 13 B 1100 14 C 1101 15 D 1110 16 E 1111 17 F
Quantities/Counting (3 of 3) Decimal Binary Octal Hexa- decimal 16 10000 20 10 17 10001 21 11 18 10010 22 12 19 10011 23 13 10100 24 14 10101 25 15 10110 26 10111 27 Etc.
Conversion Among Bases The possibilities: Decimal Octal Binary Hexadecimal
Quick Example 2510 = 110012 = 318 = 1916 Base
Decimal to Decimal (just for fun) Octal Binary Hexadecimal
Weight 12510 => 5 x 100 = 5 2 x 101 = 20 1 x 102 = 100 125 Base
Binary to Decimal Decimal Octal Binary Hexadecimal
Binary to Decimal Technique Multiply each bit by 2n, where n is the “weight” of the bit The weight is the position of the bit, starting from 0 on the right Add the results
Example Bit “0” 1010112 => 1 x 20 = 1 1 x 21 = 2 0 x 22 = 0 1 x 23 = 8 0 x 24 = 0 1 x 25 = 32 4310
Octal to Decimal Decimal Octal Binary Hexadecimal
Octal to Decimal Technique Multiply each bit by 8n, where n is the “weight” of the bit The weight is the position of the bit, starting from 0 on the right Add the results
Example 7248 => 4 x 80 = 4 2 x 81 = 16 7 x 82 = 448 46810
Hexadecimal to Decimal Octal Binary Hexadecimal
Hexadecimal to Decimal Technique Multiply each bit by 16n, where n is the “weight” of the bit The weight is the position of the bit, starting from 0 on the right Add the results
Example ABC16 => C x 160 = 12 x 1 = 12 B x 161 = 11 x 16 = 176 A x 162 = 10 x 256 = 2560 274810
Decimal to Binary Decimal Octal Binary Hexadecimal
Decimal to Binary Technique Divide by two, keep track of the remainder First remainder is bit 0 (LSB, least-significant bit) Second remainder is bit 1 Etc.
Example 2 125 62 1 12510 = ?2 2 31 0 2 15 1 2 7 1 2 3 1 2 1 1 2 0 1 12510 = 11111012
Octal to Binary Decimal Octal Binary Hexadecimal
Octal to Binary Technique Convert each octal digit to a 3-bit equivalent binary representation
Example 7058 = ?2 7 0 5 111 000 101 7058 = 1110001012
Hexadecimal to Binary Decimal Octal Binary Hexadecimal
Hexadecimal to Binary Technique Convert each hexadecimal digit to a 4-bit equivalent binary representation
Example 10AF16 = ?2 1 0 A F 0001 0000 1010 1111 10AF16 = 00010000101011112
Decimal to Octal Decimal Octal Binary Hexadecimal
Decimal to Octal Technique Divide by 8 Keep track of the remainder
Example 123410 = ?8 8 1234 154 2 8 19 2 8 2 3 8 0 2 123410 = 23228
Decimal to Hexadecimal Octal Binary Hexadecimal
Decimal to Hexadecimal Technique Divide by 16 Keep track of the remainder
Example 123410 = ?16 16 1234 77 2 16 4 13 = D 0 4 123410 = 4D216
Binary to Octal Decimal Octal Binary Hexadecimal
Binary to Octal Technique Group bits in threes, starting on right Convert to octal digits
Example 10110101112 = ?8 1 011 010 111 1 3 2 7 10110101112 = 13278
Binary to Hexadecimal Decimal Octal Binary Hexadecimal
Binary to Hexadecimal Technique Group bits in fours, starting on right Convert to hexadecimal digits
Example 10101110112 = ?16 10 1011 1011 B B 10101110112 = 2BB16
Octal to Hexadecimal Decimal Octal Binary Hexadecimal
Octal to Hexadecimal Technique Use binary as an intermediary
Example 10768 = ?16 1 0 7 6 001 000 111 110 2 3 E 10768 = 23E16
Hexadecimal to Octal Decimal Octal Binary Hexadecimal
Hexadecimal to Octal Technique Use binary as an intermediary
Example 1F0C16 = ?8 1 F 0 C 0001 1111 0000 1100 1 7 4 1 4 1F0C16 = 174148
BINARY ADDITION The following table gives the rules for binary addition. When 1 is added to 1 the sum is 10(binary)=2(decimal) A B A+B 1 10
1 In the above example when 1 is added to 1,there is a carry=1.This carry is added to the sum of the adjacent bits
Example 2 1
Binary Subtraction When 1 is subtracted from 0,there is a borrow from the adjacent bit 1
1’sComplement. The 1’s complement of a binary number is obtained by subtracting each bit of the number from 1. It is simply obtained by changing each bit 1 to zero and zero to 1 Binary number 1’s complement 100110 111110 011001 000001 10110110 11001010 01001001 00110101
2’s complement The 2’s complement of a binary number=its 1’s complement+1 10011 01100 +1 (00001) 01101 111 000 +1(001) 001 0000 1111 +1(0001) 010110 101001 +1(000001) 101010
Addition of a binary number to its 2’s complement Addition of a binary number to its 2’s complement. (In this case, the last carry is lost for a 4 bit processor) Binary number 1’s complement 2’s complement Number+2’s complement 1001 0110 0110+1=0111 1001 + 0111 0000 (carry 1 is lost)
Representation of numbers in 1’s complement Positive numbers are represented by including a zero at the extreme left. The negative numbers are represented by the complemented value of the positive signed binary. Example. +(6)10 is represented by (0110)2 -(6)10 is represented by (1001)2,the 1’s complement of (0100)2
Addition &Subtraction Using 1’s Complement There are four possibilities 1.Both the numbers are positive 2.One number is positive and the other number is negative, the negative number being greater 3.One number is positive and the is negative, the positive number being greater. 4.Both the numbers are negative.
Decimal representation Case 1. Add+0011 and +0100 Normal form Representation Decimal representation + 0011 0 0011 +3 + 0100 0 0100 +4 +0111 0 0111 + 7
Case II:One number is positive & the other number is negative, the negative number being greater. When a positive number is added to a larger negative number, the sum is the difference of the two numbers with sign of the negative number. The negative number is represented as its 1’s complement and is added to the positive number. The answer will be the complement of the sum. Normal form Representation Decimal representation + 0101 0 0101 +5 - 1100 1 0011 -12 -0111 1 1000 -7
The answer is therefore the complement of 1000 which is --0111 In the above example when the larger number is subtracted from the smaller number the result is in complemental form. The answer is therefore the complement of 1000 which is --0111 1100 -0101 0111
Case 3: When the positive number is greater, the end around carry generated should added to get the final sum. The result directly gives the sum. (no complementing needed).Example add 1110 and -1001 Normal representation Binary representation Decimal representation + 1110 0 1110 14 -1001 1 0110 -9 +0101 0 0100 (carry 1) 0 0001 0 0101 +5
Case 4: When both numbers are negative Case 4: When both numbers are negative. In this case there will be an end around carry since the numbers are added in 1’s complement form. The carry should be added to the sum.The result will be in 1’s complement form Normal representation Binary representation Decimal representation -0011 1 1000 -3 -1011 1 0100 -11 -1110 1 0000 with carry 1 1 1 0001 The final sum is the complement of the above ie -1110 -14
Addition and Subtraction using 2’s complement The addition of two positive numbers using 2’s complement representation is the same as the one described in 1’s complement method .If the numbers are opposite in sign, the method is different. If the larger number is positive, add the 2’s complement of the smaller negative number to the larger number and ignore the carry Decimal Binary 2’s complement form +9 1001 0 1001 -8 -1000 1 1000 +1 0001 1 0001 ↓ Ignore the carry The answer is
If the larger number is negative take its 2’s complement and add to the smaller positive number. It is seen that there is no carry. The sum is in 2’s complement form. To get the answer, take the 2’s complement and change the sign Decimal Binary 2’s complement method +17 10001 0 10001 -18 -10010 1 01110 -1 -00001 11111 The sum is negative and is the 2’s complement of the answer. Taking the 2’s complement of the above number1 11111 0 00000+ 0 00001
FRACTIONAL NUMBERS 1.To convert a fractional decimal number in to binary repeatedly multiply the number by two. 2.The integer part of the product of the first multiplication gives the MSB. 3.The fractional part is again multiplied by two and the integer part of the product gives the next bit. 4.The process is repeated till the product is zero. The last bit retained is the LSB
Convert 0.812510 in to binary. The operation is tabulated as follows Fractional number Product Fractional part Carry 0.8125x2 1.6250 0.6250 1 MSB 0.6250x2 1.2500 0.2500 1 0.2500x2 0.5000 0.5000x2 1.0000 0.0000 The binary equivalent of (0.8125)10 is 0.11012 .
Convert 0.11012 in to decimal 0.1101=1x(1/2)+1x(1/4)+0x(1/8)+1x(1/16) =(1/2)+(1/4)+0+(1/16) =0.5+0.25+0.0625 =0.8215
Convert 0.312510 in to binary Fractional number Product Fractional part Carry 0.3125x2 0.6250 0 MSB 0.6250x2 1.2500 0.2500 1 0.2500x2 0.5000 .05000x2 1.0000 0.0000 The required binary number 0.01012
Binary Coded Decimal Representation of decimal numbers using binary digits is defined as the binary coded decimal or BCD It is a weighted code The successive digits from right to left have specified weights The required number can be obtained by adding the products of the weights with the corresponding binary digit
Example of BCD: 8421 code This is a 4 bit BCD code The binary weights of the four bits are represented as 2³,2²,2¹, and 2 In 8421 code 16 combinations can be represented. Only 10 combinations are used to represent the decimal digits. The six combinations 1010,1011,1100,1101,1110,1111 are illegal
A decimal number can be expressed in BCD by simply replacing the digits with the corresponding 4 bit code Decimal 8421 code 5 0101 12 0001 0010 38.5 0011 0100.1000