12/2 = 6 r 0 6/2 = 3 r 0 3/2 = 1 r 1 1/2 = 0 r 1
DECIMAL-TO-BINARY
Input: an integer in decimal d
Output: an integer in binary b (you might think of this as a string)
- b = 0
- While d > 0
- r = d % 2
- d = d / 2
- b = cat(r,b) (concatenation)
- return b