Basic binary
Hellooooo everyone. I have been away for a very long time, blame school >.< BUT I’m learning some really cool things in various computer science courses this semester, so I figured I’d share some of those things with you all. I’ll probably write about one of these posts a week. I’m guessing that a disproportionate number of these posts will pertain to my computer organization class, which means I’ll be talking lots about hardware and methods of communicating with the hardware. These posts will mostly be basic, bite-sized crash-courses on the various topics, if you happen to know a lot about the topic of one of my posts then please do elaborate in the comments! Also, please ask questions if you don’t know what I’m trying to say…Sometimes my brain doesn’t work well after a certain hour, and I will probably be writing most of these posts well after that certain hour.
Anyways, today I will talk about converting decimal to binary and back again. I assume everyone is familiar with the decimal, or base-ten, numeral system. One way you could represent a number in decimal is to use positional notation, essentially breaking it up into the “one’s place”, the “ten’s place”, the “hundred’s place”, and so forth. The numbers filling each of these places can range from 0 through 9. Positional notation may be easiest to demonstrate by example. So, say you’re given a number 235. Another way to represent that number would be: (2 * 10^2) + (3 * 10^1) + (5 * 10^0), which equals 200 + 30 + 5.
Let’s take a look at binary now. Binary is the base-two numeral system, and only includes the number representations 0 and 1. Say that you’re given a 5-bit binary number 01001. This number can also be represented as (0 * 2^4) + (1 * 2^3) + (0 * 2^2) + (0 * 2^1) + (1 * 2^0). Do out the math, you’ll find that the number equals 0 + 8 + 0 + 0 + 1, which is 9. So there you have a binary representation of the number 9.
Now let’s try going from decimal to binary. A simple way to do this is to keep dividing the number by two, keeping track of the remainders as they pop up. I have no idea how to put it in better terms, so how about I just show you an example? Take the number 235. This is what it would look like to convert it to binary:
235 remainder
/2 =117 1 <–least significant digit
/2 =58 1
/2 =29 0
/2 =14 1
/2 =7 0
/2 =3 1
/2 =1 1
/2 =0 1 <–most significant digit
Notice how the remainders are all either 0′s or 1′s. Hmmmm. So, just line up those remainders in order from most significant digit to least significant digit and you get 11101011. To check that this is correct, you can write it out in positional notation:
(1 * 2^7) + (1 * 2^6) + (1 * 2^5) + (0 * 2^4) + (1 * 2^3) + (0 * 2^2) + (1 * 2^1) + (1 * 2^0)
= 128 + 64 + 32 + 0 + 8 + 0 + 2 + 1
= 235
Hooray! So that is, in a nutshell, how you convert from decimal to binary and back again. This method works for converting to any other numeral system as well (octal, hexadecimal, etc), except instead of dividing/multiplying by 2 you want to divide/multiply by the respective base number (8 for octal, 16 for hexadecimal, and so forth).




























04 Oct 2011, 11:36 pm
imo, the easiest way to understand a number system is to count in it.
for example, in binary:
0 = 0
1 = 1
10 = 2
11 = 3
100 = 4
101 = 5
110 = 6
111 = 7
1000 = 8
1001 = 9
ext…
it makes it easy to understand how each place is a value of base 2, and how you add the places to get the decimal equivalent.
05 Oct 2011, 1:16 am
I use basic binary to form cached equations in my head to make basic math easier, think of it like form new instruction sets in your brain since its basically both a CPU and storage
05 Oct 2011, 4:08 am
oh god damn my face just melted off
05 Oct 2011, 5:08 am
thats some complicated stuff
05 Oct 2011, 5:46 am
Nah. It’s quite easy actually. Octa and hexa decimals are a bit worse.
Just an example of practical use: If you have a micro controller with 8 ports and want all of them open, you give the MC the number 11111111(binary), 255(decimal) or FF(hexa decimal). What a lot of people do wrong here is calculating 11111111 to be 2^8=256. Typing this decimal number would give you the value 100000000 in binary, which would close all the ports except the non-existent ninth port.
05 Oct 2011, 8:17 am
For binary I was taught that way and then an easier way (if you think of it as an easier way)
This way requires a bit more scratch but it’s pretty helpful.
256 128 64 32 16 8 4 2 1
So you have to think of the above as some sort of yes/no system. If the number is included (and will make it add up to the decimal) then you’ll put a 1 below it, and if not a 0. So if you’re trying to get 234
256 128 64 32 16 8 4 2 1.........1 1 1 0 1 0 1 0
(formatting is a bit off because they don’t allow tons of spaces. = (but it should be 1:0 2:1 4:0 8:1 16:0 32:1 64:1 128:1)
All of where it’s 1 is a “yes” (if you think of it more as a circuit works t/f h/l y/n on/off) then the number is added, where it’s a 0 the number is ignored, so your final result is 11101010.
05 Oct 2011, 11:34 am
Hey thanks for this! I learnt binary ages ago, and have since almost forgotten it. I’ve got an assignment to do for Computing, this will probably come in handy.
05 Oct 2011, 11:46 am
Yeah I found this to be easier to understand when first learning about decimal <-> binary conversions.
05 Oct 2011, 6:07 pm
06 Oct 2011, 1:55 am
yeah thats what they taught us in cisco back in highschool
06 Oct 2011, 2:24 am
i should learn basic binary
06 Oct 2011, 8:32 pm
even if your into programming there are very few practical applications of it, but if your like me and just like learning shit like this go for it
16 Oct 2011, 8:17 pm
I’m doing this in my Computer Network Engineering Class right now! it is easy as hell