Integer Real Numbers Character Boolean Memory Address CPU Data Types Chapter 3 Integer Real Numbers Character Boolean Memory Address
Integer Integer Whole numbers No decimal places Unsigned integers Use entire by ( 8 or 6 bits) for number Lowest number is zero (0) Signed integers Use high order bit for + or – sign Octal machines have 5 bits for number (out of 6) Excess notation Hex machines have 7 bit for number (out of 8) Excess notation
Octal Integer 6 BIT number X X X X X X Weight value 32 16 8 4 2 1 All positions = “1” (“ON”) 1 1 1 1 1 1 32 16 8 4 2 1 ----- 63 Not counted: used for sign 16 8 4 2 1 ----- 31 Unsigned Signed
Hexadecimal Integer 8 BIT number X X X X X X X X Weight value 128 64 32 16 8 4 2 1 All positions = “1” (“ON”) 1 1 1 1 1 1 1 1 128 64 32 16 8 4 2 1 ----- 255 Not counted: used for sign 64 32 16 8 4 2 1 ----- 127 Unsigned Signed
Arithmetic Operations Addition Subtraction Multiplication Division
Add two numbers Addition Decimal Binary Binary bit weights 6 0110 1 + 2 + 8 = 1110 + 5 0101 ---- ------- 1110 10112
Subtract two numbers Subtraction ? Answer is: 6 - 5 ----- 0 Decimal Binary Binary bit weights 6 0110 1 + 0 + 0 + 0 = 110 - 5 - 0101 * ---- ------- 110 00002 ? 1 2 3 4 0110 -0101 ------- Borrow 1 from 2s position add to 1s position 0101 -0101 ------- Subtract 1s position 0101 -0101 ------- 0 Subtract 2s position 0101 -0101 ------- 00 5 6 7 Answer is: 6 - 5 ----- 0 Subtract 4s position 0101 -0101 ------- 000 Subtract 8s position 0101 -0101 ------- 0000
Complements Binary numbering scheme Ones (1) become zero (0) Zeros (0) become ones (1) Octal Hexadecimal 0 000 = 111 0000 = 1111 1 001 = 110 0001 = 1110 2 010 = 101 0010 = 1101 3 011 = 100 0011 = 1100 4 100 = 011 0100 = 1011 5 101 = 010 0101 = 1010 6 110 = 001 0110 = 1001 7 111 = 000 0111 = 1000 8 1000 = 0111 9 1001 = 0110 A 1010 = 0101 B 1011 = 0100 C 1100 = 0011 D 1101 = 0010 E 1110 = 0001 F 1111 = 0000
Computers MULTIPLY, SUBTRACT and DIVIDE by ADDITION Two’s Complement Computers MULTIPLY, SUBTRACT and DIVIDE by ADDITION Binary numbering scheme Used to work with negative numbers Ones (1) become zero (0) Zeros (0) become ones (1) Data is signed if: Variable data type was defined as signed in the program The number is converted in the program The computer does a Subtract or Divide Formula for conversion Original binary number Compliment the number Ones to Zeros Zeros to Ones Add binary one to lowest position High order carry's are discarded
Add two numbers Two’s Complement Decimal Binary Binary bit weights 6 0110 1 + 2 + 8 = 1110 + 5 0101 ---- ------- 1110 10112
* Two’s Compliment of 5 Subtract two numbers Two’s Complement Decimal Binary Binary bit weights 1 1 6 0110 1 + 0 + 0 + 0 = 110 - 5 +1011 * ---- ------- 110 00012 * Two’s Compliment of 5 5 = 0101 Original Compliment 1010 Add one 1 -------- Two’s compliment 1011
Subtraction Division Addition and Two’s Compliment Summary Computers do Subtraction And Division Using Addition and Two’s Compliment