CHAPTER 2
CHAPTER CONTENTS 2.1 Binary System 2.2 Binary Arithmetic Operation 2.3 Signed & Unsigned Numbers 2.4 Arithmetic Operations of Signed Numbers 2.5 Hexadecimal Number System 2.6 Octal Number System 2.7 Digital Codes 2.8 Error Detection
LEARNING OUTCOMES At the end of this chapter, you must be able to Describe the foundation for a positional number system Understand the relation between the binarydecimal number system Count in the binary system Understand the hexadecimal & octal number systems shorthand for binary number system Describe what the digital codes are Explain the error detection in digital codes
BINARY SYSTEM Binary system is used in digital systems because it is: Easy to implement Accurate 2 levels of voltage is required to represent the digits A symbol/digit in binary number system is known as a bit. bit = an acronym of binary digit. Digital circuits use binary number system to represent quantities.
BINARY SYSTEM
BINARY SYSTEM Binary to decimal conversion -As binary is a positional numbering system, each bit has different weight depending on the bits position.
BINARY SYSTEM E X A M P L E S (a) 1001101 2 = (1 2 6 ) + (0 2 5 ) + (0 2 4 ) + (1 2 3 ) + (1 2 2 ) + (0 2 1 ) + (1 2 0 ) = (1 64) + (0 32) + (0 16) + (1 8) + (1 4) + (0 2) + (1 1) = 64 + 8 + 4 + 1 = 77 10 (b) 1101100 2 = (1 2 6 ) + (1 2 5 ) + (0 2 4 ) + (1 2 3 ) + (1 2 2 ) + (0 2 1 ) + (0 2 0 ) = (1 64) + (1 32) + (0 16) + (1 8) + (1 4) + (0 2) + (0 1) = 64 + 32 + 8 + 4 = 108 10 (c) 10100 2 = (1 2 4 ) + (0 2 3 ) + (1 2 2 ) + (0 2 1 ) + (0 2 0 ) = (1 16) + (0 8) + (1 4) + (0 2) + (0 1) = 16 + 4 = 20 10
BINARY SYSTEM Decimal to Binary conversion Reverse process steps: Note that all positions must be accounted for 5 2 3710 2 0 0 2 0 2 1 0 0 1 0 12 Repeated division steps: Divide the decimal number by 2 Write the remainder after each division until a quotient of zero is obtained. The first remainder is the LSB and the last is the MSB 0
BINARY SYSTEM
BINARY ARITHMETIC OPERATION Addition Subtraction Multiplication 0 + 0 = 0 0-0 = 0 0 0 = 0 0 + 1 = 1 0-1 = 1 + 1 (borrow) 0 1 = 0 1 + 0 = 1 1-0 = 1 1 0 = 0 1 + 1 = 0 + 1 (carry) 1-1 = 0 1 1 = 1
BINARY ARITHMETIC OPERATION ADD (a) 11+11 = 110 (b) 100+10= 110 (c) 110+100= 1010 (d) 111+11= 1010 SUBTRACT (a) 11-01= 10 (b) 11-10= 01 (c) 101-011= 010
BINARY ARITHMETIC OPERATION MULTIPLICATION (a) 11 x 11 = 1001 (b) 111x101= 100011 DIVISION (a) 110/11=10 (b) 110/10=11
SIGNED & UNSIGNED NUMBERS In binary system, 3 forms of signed number are popular: - Signed-magnitude - 1 s complement - 2 s complement
SIGNED MAGNITUDE The left-most bit (MSB) is used as sign indicator. 0 Positive number 1 Negative number Example: Write -65 10 in signed magnitude form using 8-bit binary
1 S COMPLEMENT For POSITIVE number, the representation is similar to the signed magnitude form. For NEGATIVE number, the representation is the 1 s complement of the positive number, i.e. invert all the bits of its equivalent positive number 0 1 and 1 0 Example: 10110010 01001101 00011010 11100101
2 S COMPLEMENT Finding 2 s complement by adding 1 to the LSB of 1 s complement number or Using alternative method: - start from LSB, write the same bit until you find the first 1 - next take the 1 s complement of the remaining bits Example: 10110010 01001101 +1 = 01001110 10111000 10111000 01001000
RANGE OF BINARY NUMBERS UNSIGNED BINARY NUMBER All the bits are used to represent the number range 0 to 2 n 1 e.g. for 8-bit binary range 0 10 to 255 10 SIGNED BINARY NUMBER As MSB is used to indicate the sign (+ve or ve) range ( 2 n-1 ) to 2 n-1 1 e.g. for 8-bit binary range -128 10 to +127 10
ARITHMETIC OPERATIONS OF SIGNED NUMBERS The operations available for signed numbers are +,, and. However, + is mostly used in digital system. This is because most ALUs are only capable of doing the +. As the 2 s complement is widely used in computers, therefore we are going to learn the ADDITION & SUBTRACTION for 2 s complement numbers
ADDITION OF SIGNED NUMBERS There are 4 cases that can occur 1.Both numbers are positive + number 2.Positive number with magnitude larger than negative number + number 3.Positive number with magnitude smaller than negative number - number 2 s C 4.Both numbers negative overflow * add the numbers and discard the final carry bit
ADDITION OF SIGNED NUMBERS Case 1: 00000111+00000100 = 00001011 Case 2: 00001111+11111010 = 100001001 Case 3: 00010000+11101000 = 11111000 Case 4: 11111011+11110111 = 111110010 ** Overflow case If the sign bit result is different than the sign bit of the numbers added, overflow is indicated Eg: 01111101+00111010 = 10110111
SUBTRACTION OF SIGNED NUMBER It is a special case of addition i.e. take the two signed numbers, take the 2 s complement of the subtrahend and add. Discard carry bit. Meaning we have to change the sign of subtrahend using 2 s complement form. Example: 00001000 00000011 11111101 00001000+11111101 = 100000101 Example: 11100111-00010011 11101101 11100111 + 1110110 = 111010100
MULTIPLICATION OF SIGNED NUMBERS Step 1 determine the sign (+/-) ** if - then must also use 2 s complement. Since we use only true form. Step 2 perform 2 s complement to multiplier Step 3 perform multiplication to magnitude bit If multiplier 1 follows multiplicand value If multiplier 0 become 0 Step 4 add each result with the sum of previous partial product. Shift left one bit. Step 5 if the sign in step 1 is negative, take 2 s complement of the product. Attach the sign bit 1
HEXADECIMAL NUMBER SYSTEM Also known as BASE 16 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, A, B, C, D, E, F It is a positional numeral system. Example: Given a hexadecimal number of 4A9 For digit 4 4 x 16 2 digit A A (=10) x 16 1 digit 9 9 x 16 0
BINARY TO HEXADECIMAL CONVERSION Each hexadecimal digit = 4 bits (or 1 nibble) To convert, group the binary number in groups of 4 (starting with LSB) then write down the equivalent hexadecimal digit
BINARY TO HEX HEX TO BINARY
HEXADECIMAL TO DECIMAL CONVERSION 79 16 = (7 16 1 ) + (9 16 0 ) = (7 16) + (9 1) = 112 + 9 = 121 10 E0 16 = (14 16 1 ) + (0 16 0 ) = (14 16) + (0 1) = 224 = 224 10 AB 16 = (10 16 1 ) + (11 16 0 ) = (10 16) + (11 1) = 160 + 11 = 171 10
DECIMAL TO HEXADECIMAL CONVERSION
OCTAL NUMBER SYSTEM Also known as BASE 8 0, 1, 2, 3, 4, 5, 6, 7 It is a positional numeral system. Example: Given an octal number of 463 For digit 4 4 x 8 2 digit 6 6 x 8 1 digit 3 3 x 8 0
BINARY TO OCTAL OCTAL TO BINARY
OCTAL TO DECIMAL CONVERSION 2 1 1638 1 (8 ) 6 (8 ) 3 (8 1 64 48 3 1 115 10 0 ) 2374 8 3 2 1 0 (2 8 ) (3 8 ) (7 8 ) (4 8 ) ( 2 512) (3 64) (7 8) (4 1) 1276 10
DECIMAL TO OCTAL CONVERSION
HEXADECIMAL TO OCTAL CONVERSION
OCTAL TO HEXADECIMAL CONVERSION
DIGITAL CODES Encode a process where numbers, letters or words are represented by a special group of symbols. Code the group of symbols Several types of Digital Code Binary-Coded-Decimal (BCD) Code Gray Code ASCII Code
BINARY CODED DECIMAL (BCD CODE) Since the largest decimal is 9 10 (=1001 2 ), therefore 4 bits are required to code each decimal s digit. BCD is not a number system. BCD is a decimal number with each digit encoded to its binary equivalent. BCD number is not the same as a straight binary number.
BCD CODE The primary advantage of BCD is the relative ease of converting to and from decimal. Each digit always uses four bits. The BCD value can never be greater than 9 Reverse the process to convert BCD to decimal. Example: Write the BCD code for 579 10. Ans: The BCD code is 0101 0111 1001
BCD CODE DECIMAL TO BCD 3 5 0 0 1 1 0 1 0 1 1 7 0 0 0 0 1 0 1 1 1 0 0 0 0 BCD TO DECIMAL 0 0 1 1 0 1 0 1 0 0 0 1 3 5 1 1 0 0 0 0 1 1 0 8 6
GRAY CODE Gray code is a way to represent a sequence of numbers. Important feature: only 1 bit is changed at a time Purpose of using this code: to minimise the error when counting in sequence
BINARY TO GRAY CODE CONVERSION
GRAY CODE TO BINARY CONVERSION
AMERICAN STANDARD CODE FOR INFORMATION INTERCHANGE (ASCII CODE) ASCII codes represent text in computers, communication devices, etc. It is an alphanumeric code with 2 7 (i.e. 128) possible code groups. meaning a code is consists of 7-bit binary As most computers deal with 8-bit binary group, normally an 8 th bit is commonly used as a parity bit.
ASCII CODE
ERROR DETECTION There is a possibility that errors can occur during data transmission. DATA SEND DATA RECEIVED Major cause electrical noise (spurious fluctuation in voltage or current) Due to the large size of data, many digital systems employ some method to detect (and sometimes to correct) the error. e.g. Parity bit method
PARITY BIT Parity bit is an extra bit attached to a code group that is being transferred. There are 2 types of parity method: EVEN-parity method ODD-parity method Parity bit could be 1 or 0 depending on the number of 1s available in the code (and also what type of parity method is employed)
EVEN PARITY The value of the parity bit is chosen so that the total number of 1s in the code group (including the parity bit) is an even number. Example: A code 1000011 is to be sent to a printer. What is the parity bit to be attached to the code if an even parity method is employed? Solution: Number of 1s in the code = 3. Therefore, a parity bit of 1 is used. Now, total number of 1s = 4 (even) Code sent = 1100 0011
ODD PARITY The value of the parity bit is chosen so that the total number of 1s in the code group (including the parity bit) is an odd number. Example: A code 1000011 is to be sent to a printer. What is the parity bit to be attached to the code if an odd parity method is employed? Solution: Number of 1s in the code = 3 (odd) Therefore, a parity bit of 0 is used. Code sent = 1100 0011