Download presentation
Presentation is loading. Please wait.
1
Binary numbers and arithmetic
2
Addition (decimal)
3
Addition (binary)
4
Addition (binary)
5
Multiplication (decimal)
6
Multiplication (binary)
7
Multiplication (binary)
It’s interesting to note that binary multiplication is a sequence of shifts and adds of the first term (depending on the bits in the second term. The first term is missing here because the corresponding bit in the second terms is 0.
8
Representing numbers (ints)
Fixed, finite number of bits. bits bytes C/C++ Intel Sun char [s]byte byte short [s]word half int or long [s]dword word long long [s]qword xword
9
Representing numbers (ints)
Fixed, finite number of bits. bits Intel signed unsigned 8 [s]byte 16 [s]word 32 [s]dword 64 [s]qword In general, for k bits, the unsigned range is [0..+2k-1] and the signed range is [-2k-1..+2k-1-1].
10
Methods for representing signed ints.
signed magnitude 1’s complement (diminished radix complement) 2’s complement (radix complement) excess bD-1
11
Signed magnitude Ex. 4-bit signed magnitude 1 bit for sign
3 bits for magnitude
12
Signed magnitude Ex. 4-bit signed magnitude 1 bit for sign
3 bits for magnitude
13
1’s complement (diminished radix complement)
Let x be a non-negative number. Then –x is represented by bD-1+(-x) where b = base D = (total) # of bits (including the sign bit) Ex. Let b=2 and D=4. Then -1 is represented by = 1410 or
14
1’s complement (diminished radix complement)
Let x be a non-negative number. Then –x is represented by bD-1+(-x) where b = base & D = (total) # of bits (including the sign bit) Ex. What is the 9’s complement of ? Given b=10 and D=5. Then the 9’s complement of 12389 = 105 – 1 – 12389 = – 1 – 12389 = – 12389 = 87610
15
1’s complement (diminished radix complement)
Let x be a non-negative number. Then –x is represented by bD-1+(-x) where b = base D = (total) # of bits (including the sign bit) Shortcut for base 2? Ex. Let b=2 and D=4. Then -1 is represented by = 1410 or
16
2’s complement (radix complement)
Let x be a non-negative number. Then –x is represented by bD+(-x). Ex. Let b=2 and D=4. Then -1 is represented by 24-1 = 15 or Ex. Let b=2 and D=4. Then -5 is represented by 24 – 5 = 11 or Ex. Let b=10 and D=5. Then the 10’s complement of = 105 – = – =
17
2’s complement (radix complement)
Let x be a non-negative number. Then –x is represented by bD+(-x). Ex. Let b=2 and D=4. Then -1 is represented by 24-1 = 15 or Ex. Let b=2 and D=4. Then -5 is represented by 24 – 5 = 11 or Shortcut for base 2?
18
excess bD-1 For pos, neg, and 0, x is represented by
bD-1 + x. Ex. Let b=2 and D=4. Then the excess 8 (24-1) representation for 0 is 8+0 = 8 or Ex. Let b=2 and D=4. Then excess 8 for -1 is 8 – 1 = 7 or
19
excess bD-1 For pos, neg, and 0, x is represented by
bD-1 + x. Ex. Let b=2 and D=4. Then the excess 8 (24-1) representation for 0 is 8+0 = 8 or Ex. Let b=2 and D=4. Then excess 8 for -1 is 8 – 1 = 7 or
20
Summary of methods for representing signed ints.
21
Representing numbers (ints)
Fixed, finite number of bits. bits Intel signed 8 sbyte 16 sword 32 sdword 64 sqword In general, for k bits, the signed range is [-2k-1..+2k-1-1]. So where does the extra negative value come from?
22
Representing numbers (ints)
Fixed, finite number of bits. bits Intel signed 8 sbyte 16 sword 32 sdword 64 sqword In general, for k bits, the signed range is [-2k-1..+2k-1-1]. So where does the extra negative value come from?
Similar presentations
© 2025 SlidePlayer.com. Inc.
All rights reserved.