created: 07/15/2015; improved 04/10/16; improved again 04/22/23
The algorithm is:
number = positive integer ; bitstring = "" while (number > 0 ) { bit = number mod 2 ; append bit to the left of bitstring; quotient = number div 2 ; number = quotient ; } mod means remainder after integer division. div means quotient after integer division.
Positive Integer: | |
---|---|
Number: | |
bit = Number Mod Two | |
Bit String | |
quotient = Number Div Two | |
number = quotient |
To start: Enter a decimal representation of a not too big positive integer in the Positive Integer box.
Then: Click Initialize to assign the integer to number.
Then: Click Divide by Two to compute the quotient and remainder. The remainder will be 0 or 1. That bit is copied to the left of the bit string.
Click Repeat to go through the cycle again. Quit when the number has been reduced to zero.
The algorithm is:
number = decimal fraction ; bitstring = "." while ( number > 0 ) { number = number * 2 ; bit = 1 or 0 left of the decimal point ; append bit to the right of bitstring ; number = digits right of the decimal point ; }
Positive Decimal Fraction: | |
---|---|
Number: | |
Number = Number * 2 | |
bit = bit in 1's place | |
bit String = bit String + bit | |
number = digits right of point |
To start: Enter a decimal representation of a fraction in the Positive Decimal Fraction box.
Then: Click Initialize to assign the fraction to number.
Then: Click Multiply by Two . A bit will appear in the 1's place. That bit will be 0 or 1. Copy it to the right of the bit string.
Click Repeat to go through the cycle again. Quit when the fraction is zero or you have enough bits.