Download presentation
Presentation is loading. Please wait.
Published byGladys Potter Modified over 9 years ago
1
Binary Representation - Shortcuts n Negation x + x = 1111…1111 two = -1 (in 2’s complement) Therefore, -x = x + 1 n Sign Extension o Positive numbers : easy o Negative numbers (2’s complement): - 4 in 4 bits : 1100 - 4 in 5 bits : 11100 Why is this useful? 1. Actual sign extension 2. Binary to decimal conversion (2’s complement) -- can forget about leading 1’s e.g. 1111 1110 two = 110 two = -2 ten
2
Negative Binary to Decimal n Change sign (2’s compliment) 1111 1111 1011 0100 two = - 0000 0000 0100 1100 two = - 76 Changing sign What pattern appears at the right end ? 1 followed by some (or no) 0’s o Trick: retain that pattern and flip everything to the left of it e.g. - 1111 1100 0000 0000 = 0000 0100 0000 0000
3
A Feel for Base 2 n What is multiplication by 2 ? 5 x 2 = 10 ten 101 two x 2 = ? (can you use this in efficiently solving 4.11?) n What is division by 2, ignoring any remainder? 0000 0101 two / 2 = ? 1110 0010 two / 2 = ? n What does a multiple of 4 look like? 4 = 0000 0100 24 = 0001 1000 60 = 0011 1100 All end in 2 zeros. Why?
4
“Translate Binary to Hexadecimal” n Binary and Hex are two different representations n Can convert from one to the other treating numbers as a series of bits n Need not worry about signed/unsigned, 2’s complement, 1’s complement, etc n Make groups of 4 bits, starting from the right n Add 0’s to the left if necessary (do not sign extend) n Translate each group of 4 bits to hex individually e.g. 01110000100101 two = 0001 1100 0010 0101 two = 1c25 hex
5
“Bits have no inherent meaning” n “Value” of a binary number depends on how you look at it n e.g. consider the 4 bit number 1110 two n unsigned:14 n signed:??? (can assume 2’s complement) n 2’s complement :- (0010 two ) = -2 n 1’s complement:- (0001 two ) = -1 n sign and magnitude:- (110 two ) = -6
6
Overflow and Underflow n Assume 4 bit numbers in 2’s complement form n Range : - 2 3 to (2 3 - 1), or - 8 to 7 n 7 + 5 = 12 ……… cannot represent 12 using 4 bits (signed) ! n What happens in binary addition ? 0111(7) + 0101(5) = 1100(-4) The number “appears” to be negative because it is out of range n Similarly, 7 - (-5) = 12 ……. out of range n Underflow: (-7) + (-5) = -12 ……. negative number out of range n Remember : overflow/underflow can occur only when 1. Numbers of same sign are added 2. Numbers of opposite signs are subtracted
Similar presentations
© 2025 SlidePlayer.com. Inc.
All rights reserved.