Celtic Kane

How does the binary system work?

It’s just like all base systems work. Binary is a base system of 2, where there’s two possible values in each digit (0 and 1). We use a base system of 10, where each digit has ten possible values (0-9). In the binary system, each digit that you move to the left, it counts as a power of two. First I would like to show you visually what’s going on with binary numbers…

___ ___ ___ ___ ___
2^4 = 16 2^3 = 8 2^2 = 4 2^1 = 2 2^0 = 1

Basically what happens is you find all your 1 values, determine their corresponding values, then add. For example, if you had 11111 (like in the example above) you would add 16+8+4+2+1 — which equals 31. Therefore, the value of the binary number “11111” equals the base 10 decimal number of “31”.

More examples converting binary to decimal

Binary -> 101

Decimal: Okay, let’s look at the digits. You always read binary numbers from right to left. The right-most digit is a 1, and it’s corresponding value is 2^0, which is 1. The next digit is a 0, so we ignore it’s value. The next digit (and the left-most) is a 1, and it’s corresponding value is 2^2, which is 4. So we add up our values…1 + 4 = 5. Therefore, the binary number 101 is equivalent to the decimal number of 5.

Why use 0’s if their values don’t count?

0’s are just placeholders. In the example above, if we just took out the zero, our binary number would be “11” and its value would be 2^0 + 2^1 — which would be 3, not 5.

Binary -> 10101

Decimal: 2^0 + 2^2 + 2^4 = 1 + 4 + 16 = 21

Binary -> 010

Decimal: 2^1 = 2
Remember…we ignore 0’s and they are just placeholders…if there aren’t any 1’s to the left of a zero, then that zero is irrelevant. Therefore, then binary number 0101 is equivalent to 00000101.

Binary -> 1000

Decimal: 2^3 = 8

Binary -> 0000111

Decimal: 2^0 + 2^1 + 2^2 = 7

This section was not intended to teach you binary — you should have some background on it already. This was meant as a refresher for anyone who was rusty on their binary to decimal conversions.

Are negative binaries possible?

Absolutely! Unfortunately you can’t just stick a negative sign in front of a binary number…it just doesn’t work like that. There are three methods used to make a binary number negative, but the only catch is in order to read a negative binary you have to know which method the binary number is using to be negative. The three methods I’ve seen are signed magnitude, one’s complement, and two’s complement.

Negatives #1: Signed Magnitude

This is by far the easiest method to use. If you know you have a signed magnitude binary number, you just look at the left-most bit. If it’s a 0, then the number is positive…if it’s a 1, the number is negative. This method only works if you know exactly how long the binary word is supposed to be. After you determine if the number is positive or negative, ignore the left-most bit and convert to decimal.

Binary -> 0111

It must be positive since the first (left-most) bit is a 0. The next three bits are 111, which converts to 2^0 + 2^1 + 2^2 = positive 7

Binary -> 1001

It must be negative since the left-most bit is a 1. The next three bits are 001, which converts to 2^0 = negative 1

Negatives #2: One’s Complement

This method is a little more difficult, but works on a similar principle. If the left-most bit is a 1, then flip all the bits (0’s turn to 1’s, and 1’s turn to 0’s) — the number will be negative. If the left-most bit is a 0, do NOT flip any of the bits and read the binary word as a positive number.

Binary -> 1001

Since the left-most bit is a 1, we need to flip our bits. Our new binary word is 0110, and when we convert to decimal we get 2^1 + 2^2 = negative 5.

Binary -> 0111

Since the left-most bit is a 0, we do not flip our bits. This is a normal, positive number…2^0 + 2^1 + 2^2 = positive 7.

Negatives #3: Two’s Complement

This is probably the most common — in fact, I haven’t seen method #1 or #2 on a WYSE test before — but it’s always good to know them anyway. In two’s complement, you follow the exact same rules except when you flip your bits for a negative number, you must add 1.

Binary -> 1001

It’s left-most bit is a 1, so we’ll flip it and we’ll get: 0110. However, we have to add 1, so our final number will be 0111, which converts to a negative 7.

Binary -> 1100

It’s left-most bit is a 1, so we’ll flip it and get 0011….after adding 1, we’ll get 0100, which converts to negative 4.

Binary -> 00011

It’s left-most bit is a 0, so we don’t flip anything and we don’t add anything… Our decimal value is 2^0 + 2^1 = positive 3.

Fractional Binaries

Fractional binary numbers (binary numbers that represent fractions) are theoretical only — computers do not use them. But it’s kind of fun to mess around with them anyways. If you truly understand how the base 2 system works, then it will make sense that if you have a decimal point and number after the decimal point will have a decreasing power of two.

___ ___ . ___ ___ ___
2^1 = 2 2^0 = 1 2^-1 = 1/2 2^-2 = 1/4 2^-3 = 1/8

There really is no complexity to this, so I’m not going to go into further detail. If you’re still confused, check out some of the examples.

Binary -> 10.01

Decimal: 2^1 + 2^-2 = 2 + 1/4 = 9/4

Binary -> 1.1

Decimal: 2^0 + 2^-1 = 1 + 1/2 = 3/2

Binary -> 111.111

Decimal: 2^2 + 2^1 + 2^0 + 2^-1 + 2^-2 + 2^-3 = 4 + 2 + 1 + 1/2 + 1/4 + 1/8 = 7.875

Even/Odd Parity

Computers can sometimes make errors when they transmit data. Even/odd parity is an extremely basic method of detecting if an odd number of bits have been switched by accident. In even parity, the number of 1’s must add up to an even number — likewise, an odd parity means the number of 1-bits must add up to an odd number. The computer knows which parity it’s using, so if it’s using an odd parity and it counts an even number of 1-bits, then it knows there was an error. However, nothing is fool proof. If an even number of bits are flipped, then the parity will still be the same. In other words, if you meant to have 4 bits, and two of them flipped so now you have 2 bits, you still have an even parity but an error occured.
What happens if you have a binary word that has an odd number of bits but you need even parity? That’s where the parity bit comes in… Let’s assume you’re trying to send an 8-bit binary word (8 digits). If you need to change the parity to even, you just add a parity bit (1 digit) to the left-side of the binary word. Now you have a 9-bit word, but the comptuer knows ahead of time to ignore the left-most bit. Let’s do some examples to make this more concrete.

You receive the binary word “0101” and you know you’re using odd parity. Is the binary word errored?

Yes. There are 2 1-bits, which is an even number. We’re using odd parity, so there must have been an error.

What should the binary word “1010” look like after you add a parity bit? You’re using an odd parity.

Right now there’s an even number of 1-bits, so we need to add another 1… Our new word will be “11010”

What should the binary word “1010” look like after you add a parity bit? You’re using an even parity.

We already have an even number of 1-bits, so we don’t want to add any more. We must add a parity bit because the computer will be expecting it, so our new word will be “01010”

Conclusion

This should adequately train you to understand binary numbers and how to deal with them. In the next lesson, you’ll learn how to deal with other bases besides 10 (the one we use every day) and 2 (the binary system). Things will get a little more difficult with other bases, but it’s still not a big deal once you know how it works.


Next: Octal and Hexidecimal
Previous: Back to Table of Contents