Introduction to binary and ones compliment

binary (base 2) representation of numbers


Computer systems use binary to represent data because the billions of switches known as transistors inside the computer’s processor can only be either on or off. This means that because binary is base 2 meaning it only has two characters, either a 0 or a 1, it is useful for representing the on or off state of the transistors. As computers need to use the on and off state to transmit data they string together binary characters in different sequences. These sequences, referred to as binary numbers, are how the machines get around the limiting factor of having a language with only two characters in it.


The difference between bits and bytes


A bit and a byte are two different units of measurement. A byte is always 8 times the size of its bit equivalent. For example, a megabyte is the size of 8 megabits and a gigabyte is the size of 8 gigabits. You can usually tell if something is measured in bits or bytes by looking at how it is displayed. In most cases, a capital letter refers to a byte and a lowercase letter refers to a bit. MB would refer to a megabyte and Mb would refer to megabit while some people might look at these and think they are the same 1Mb is actually one 8th of 1MB.


One’s Complement, Two’s Complement, and Sign Magnitude


One’s Complement, two’s complement, and signed magnitude are three different methods of extending the mathematical capabilities of binary numbers. Standard binary numbers work fine if they are representing positive numbers only, or if you are performing addition only using positive numbers. This is very limiting so one’s Complement, two’s complement, and signed magnitude were invented as different ways to allow us to represent and work with negative numbers as well as subtraction.

All three of these methods work but each method comes with its own drawbacks. For instance, one’s complement method needs both a positive zero and a negative zero.

010 = 2
001 = 1
000 = 0
111 = -0
110 = -1
101 = -2

The two’s complement method removes the need for a second zero but then the person using this method must remember that the negative zero has been removed and must remember to increment all their negative numbers by 1 to account for this.

011 = 3
010 = 2
001 = 1
000 = 0
111 = -1
110 = -2
101 = -3

The sign-magnitude method solves both problems by instead using the most prominent binary digit, the first on the left, as a way of indicating if the number is positive or negative. If the far-left digit is a zero, this indicates that the number is positive and if it is a one then this indicates that the number is a negative number. Unfortunately, because with sign-magnitude we must use the far-left digit as an indicator, this means the maximum size of the numbers we can use is reduced. So if we were using sign magnitude to four binary places instead of the highest number being 15 it would now be 7 as the far-left digit which would normally represent 8 is now being used to indicate if the number is positive or negative.

0011 = +3
0010 = +2
0001 = +1
0000 = 0
1001 = -1
1010 = -2
1101 = -3