Binary Arithmetic & Data representation
Addition 0 + 0 = 0 0 + 1 = 1 1 + 0 = 1 1 + 1 = 0 , with carry 1 1 + 1 + 1 = 1 , with carry 1 Example 1 0 0 1 1 1 + 1 1 0 1 1 10 0 0 0 1 0
Subtraction Example 1 0 1 0 1 - 1 1 1 0 0 0 1 1 1 0 - 0 = 0 1 - 0 = 1 1 - 1 = 0 0 - 1 = 1 , with borrow 1 [same as borrowing 1 from next column 10-1=1] Example 1 0 1 0 1 - 1 1 1 0 0 0 1 1 1
Multiplication Example 1 0 1 0 x 1 0 0 1 0 0 0 0 1 0 1 1 0 1 0
Division 0 / 1 = 0 1 / 1 = 1 Example 110 ) 100001 ( 0101 110 1000 100 1001 11
Subtraction by addition Computers store negative numbers in the form of their arithmetic complements. Computers’ use 2’s complement form. Example, binary form 11100011 1’s complement 00011100 2’s complement 00011101 We will use 2’s complement for subtraction. First convert the negative number into 2’s complement form. Then add it to the other number.
Example, 11110000 (B=11110000=240) + 01110010 (A=10001110=142) 1 01100010 (Result=98) Discard 10111 (B=01001=9) + 00100 (A=00100=4) 11011 (Result=-5) 2’s complement of 11011=00101=5
Numeric data representation An integer or fixed point number has no decimal point. An integer I is represented in the memory of the computer by its binary form if I is positive or by its 2’s complement if I is negative.
BCD code Another way to represent numerical data is to convert each decimal digit to its corresponding binary format. 4 bits are needed to code each decimal digit. Its called binary coded decimal (BCD). Example, 469 0100 0110 1001
Alphanumeric codes There are two 8-bit alphanumeric codes, ASCII (American Standard Code for Information Interchange) and EBCDIC (Extended Binary-Coded Decimal Interchange Code). ASCII codes have a zone part. The 16-bit Unicode is becoming popular. Unicode supports international languages.