Date: Thu, 18 Oct 2001 11:46:06 -0500 (CDT) From: Mark Jacobson To: 810-080-01@uni.edu, 810-080-02@uni.edu Subject: Base 10 to base 2 (binary) Hi discrete students, For converting from base 10 decimal to base 2 binary, one approach is the following: 1. Write down the powers of two in reverse order until you get to the largest power of two that is smaller than or equal to the base 10 number. For example, 327 256 128 64 32 16 8 4 2 1 2. Subtract this power of two from the base 10 number, write the digit 1 down to represent it, and take the remaining value and find the next largest power of 2 you can remove from it. Write 0's down until that power of 2, then write a 1. Subtract that next power of two and continue this process until done. 256 128 64 32 16 8 4 2 1 1 327 -256 ---- 71 We can now take 64 out of 71, so the 128 digit will be 0, and the 64 digit will be 1. 71 -64 --- 7 256 128 64 32 16 8 4 2 1 1 0 1 Since 4 is the next highest power of 2 we can remove from the value 7, we can write 0001 as the next digits, since there are 0 32s, 0 16s, 0 8s and 1 4s in the value 7. 256 128 64 32 16 8 4 2 1 1 0 1 0 0 0 1 -------- 7 -4 -- 3 in binary, 3 is 11 so just fill in the 11 to finish. 10 2 256 128 64 32 16 8 4 2 1 1 0 1 0 0 0 1 1 1 Thus, 327 = 101000111 10 2 For converting from a binary number value, to the base 10 value, here is one approach that works: What is binary 1011001110 when converted to base 10 decimal? 2 1 0 1 1 0 0 1 1 1 0 512 256 128 64 32 16 8 4 2 1 --- --- -- - - - 512 + 128 + 64 + 8 + 4 + 2 = 718 Here is the bc calculator verification of the above two results. Recall that obase=2 sets the output base to be binary, base 2. The bc calculator has default obase=10, naturally! venkman@julia:~/web$ bc 512+128+64+8+4+2 718 obase=2 718 1011001110 327 101000111