Cryptography Reference
In-Depth Information
Of course, when writing numbers in decimal we do not normally use any leading
zeros.
A.1.2
Binary
We now look at binary numbers.
WRITING A NUMBER IN BINARY
Binary numbers
are numbers written in base 2. Binary numbers follow very similar
rules to decimal numbers. In fact the only real change is that the role of the number
10 inwriting a decimal number is replaced by the number 2. Thus the newrules are:
1. The digits of a binary number can take the value 0 or 1.
2. Every digit in a binary number will be multiplied by some power of 2. The
powers of 2 start with 0 (the furthest digit to the right) and then increase from
right to left.
Consider the binary number 1101
2
(note that we have used the subscript 2 just to
make it clear that wemean the number 1101 in binary and not the decimal number
one thousand one hundred and one, which we would have written 1101
10
). Using
the above rules (and comparing them with the explanation of decimal numbers),
we see that each binary number is a sum of multiples of powers of 2:
2
3
)
2
2
)
2
1
)
2
0
)
1101
2
=
(1
×
+
(1
×
+
(0
×
+
(1
×
.
Similarly, the number 110010
2
is the sum of multiples of powers of 2 expressed
by:
2
5
)
2
4
)
2
3
)
2
2
)
2
1
)
2
0
)
110010
2
=
(1
×
+
(1
×
+
(0
×
+
(0
×
+
(1
×
+
(0
×
.
Every binary number has a decimal equivalent, and every decimal number has a
binary equivalent. We now explain how to convert from one to the other.
CONVERTING BINARY TO DECIMAL
Converting from binary to decimal is easy. Simply express the binary number as
its sum of multiples of powers of 2, and then add them up. So, what is 1101
2
in
decimal? We know that:
1101
2
=
(1
×
2
3
)
+
(1
×
2
2
)
+
(0
×
2
1
)
+
(1
×
2
0
)
=
(1
×
8)
+
(1
×
4)
+
(0
×
2)
+
(1
×
1)
=
8
+
4
+
0
+
1
=
13
.
So what we are saying is that the number 1101 in binary is the same as the number
13 in decimal, in other words 1101
2
=
13
10
.