To convert from decimal to binary, subtract off powers of 2, and if the result is positive, write a 1. Otherwise write a 0. This method assumes that the highest power of 2 needed for this conversion is already known. Making a reasonable guess isn't hard if the powers of 2 are consulted. An alternate way, a straightforward algorithm, is to start with the 0th power of 2, 1, and subtract it. If the result is positive, guess higher. Continue this until a negative number is obtained, then back off to the previous power of 2. Here is a table of some of the powers of 2: n n n n 2 n 2 n 2 ------------------------------------------------------------------ 0 1 11 2048 22 4,194,304 1 2 12 4096 23 8,388,608 2 4 13 8192 24 16,777,216 3 8 14 16,384 25 33,554,432 4 16 15 32,768 26 67,108,864 5 32 16 65,536 27 134,217,728 6 64 17 131,072 28 268,435,456 7 128 18 262,144 29 536,870,912 8 256 19 524,288 30 1,073,741,824 9 512 20 1,048,576 31 2,147,483,648 10 1024 21 2,097,152 32 4,294,967,296 |