1
CS240 Computer Organization
Department of Computer Science Wellesley College
Numeric Representation
Two's complement and friends
Numeric representation 4-2
Our mutual friend
- Conversion to and from
hex is not too BAD16 = __________10.
- Octal is also useful*
0, 1, 2, 3, . . .
- Why do machine language
programmers confuse Halloween with Christmas?
*And the same conversion trick works between binary and octal. Why?
Numeric representation 4-3
Frankly, other conversions are no where as nice ...
- Given a number num, we find dn dn-1 ... d1 d0 so that
num = dn rn + dn-1 rn-1 + ... + d1 r1 + d0 r0
- The algorithm* is simple, but tedious.
for i ← 0 to n
- dodi ← num mod r
- num ← num div r
*num = dn rn-1 + ... + d1 r 1 + d0 r0 = (num div r) *r + (num mod r). Repeat.
Numeric representation 4-4
Arithmetic is the same everywhere
Addition 100112 + 001012 Subtraction CDB16
- C3E16