CSE 111, Fall 2004
ALGORITHM: DECIMAL D TO 8-BIT BINARY B
-
Make a table with columns labeled:
(1) Decimal numeral being considered
(2) How many of these (in column (1)'s number)?
(3) Resulting bit
-
a) Write D in column (1);
b) Write 128 (= 8th bit's place) in column (2);
c) Do D ÷ 128;
d) Get quotient Q & remainder R;
e) Write Q in column (3)
-
Repeat (until column 2 = "1")
(i.e., until all bits are computed):
a) Write the current R in column (1);
b) Write bit-place number in column (2);
(find it by halving column 2)
c) Call it N;
d) Do R ÷ N;
e) Get quotient Q & remainder R;
f) Write Q in column (3)
-
Let
b8, b7, ..., b1
be the numerals in column (3),
from top to bottom
Then B =
b8 b7 ... b1.
Copyright © 2004 by
William J. Rapaport
(rapaport@cse.buffalo.edu)
file: 111F04/dec2bin-alg-2004-08-25.html