The TCP/IP Guide - Version 3.0 (Contents) ` 131 _ © 2001-2005 Charles M. Kozierok. All Rights Reserved.
Binary, Octal and Hexadecimal Arithmetic
Many of us use arithmetic every day as part of our regular lives without really noticing it, to
give us the information we need to make decisions. In a similar way, computers perform
arithmetic operations all the time as part of their normal operation. The main differences
between how computers do it and how we do it are two-fold: computers use binary
numbers, and computers are much faster.
As I said in my introduction to binary, octal and hexadecimal numbers, those forms are
different representations of numbers, and are not really much different than decimal
numbers. They just have a different number of values per digit. In a similar vein, arithmetic
with binary, octal or hexadecimal numbers is not that much different from the equivalent
operations with decimal numbers. You just have to keep in mind that you are working with
powers of 2, 8 or 16, instead of 10, which isn’t always easy to do.
As was the case with conversions, calculators are usually the way to go if you need to do
math with binary, octal or hexadecimal numbers. If your calculator only does math with
decimal numbers, one trick is to convert the numbers to decimal, then perform the
operation, and convert back the result. However, you can fairly easily do the same addition,
subtraction, multiplication and division on binary, octal or hex numbers that you do with
decimal numbers, by using the Windows Calculator program or equivalent.
Multiplication and division of binary numbers is a common operation within computers, but
isn't a calculation that often needs to be done by people who are working with them.
Addition and subtraction are much more common (especially addition), and have the added
bonus of being much easier to explain. You probably won't need to do this type of arithmetic
that often, but it's good to understand it, at least a little. I am going to provide just a couple
of examples to give you the general idea.
Binary Arithmetic
Let's start with binary. Adding binary numbers is the same as adding decimal ones, but you
end up doing a lot of carrying of ones since there are so few values allowed per digit. Table
8 shows an example, with one digit in each column; read it from right to left and top to
bottom, just as you would usually do manual addition. So we start by adding the "1" in the
"ones" place from the first number with the "1" in that place from the second number,
yielding a raw digit sum of 2. This means the result for the "ones" digit is "1" and we carry a
1 to the "twos" place. We continue with this process until we have added all the digits.
Table 8: Binary Addition
Carry 11 11—
First Binary Number 1 0 1 1 0 0 1 1
Second Binary Number 00111001
Raw Digit Sum 1 1 3 2 1 1 2 2