Please Whitelist This Site?
I know everyone hates ads. But please understand that I am providing premium content for free that takes hundreds of hours of time to research and write. I don't want to go to a pay-only model like some sites, but when more and more people block ads, I end up working for free. And I have a family to support, just like you. :)
If you like The TCP/IP Guide, please consider the download version. It's priced very economically and you can read all of it in a convenient format without ads.
If you want to use this site for free, I'd be grateful if you could add the site to the whitelist for Adblock. To do so, just open the Adblock menu and select "Disable on tcpipguide.com". Or go to the Tools menu and select "Adblock Plus Preferences...". Then click "Add Filter..." at the bottom, and add this string: "@@||tcpipguide.com^$document". Then just click OK.
Thanks for your understanding!
Sincerely, Charles Kozierok
Author and Publisher, The TCP/IP Guide
|
NOTE: Using software to mass-download the site degrades the server and is prohibited. If you want to read The TCP/IP Guide offline, please consider licensing it. Thank you.
|
|
|
|
Binary, Octal and Hexadecimal Arithmetic
(Page 2 of 2)
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 7
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 7: Binary Addition
Carry
|
|
1
|
1
|
|
|
1
|
1
|
|
First Binary
Number
|
1
|
0
|
1
|
1
|
0
|
0
|
1
|
1
|
Second Binary Number
|
0
|
0
|
1
|
1
|
1
|
0
|
0
|
1
|
Raw Digit
Sum
|
1
|
1
|
3
|
2
|
1
|
1
|
2
|
2
|
Result
|
1
|
1
|
1
|
0
|
1
|
1
|
0
|
0
|
Carry to
Next Higher Digit
|
|
|
1
|
1
|
|
|
1
|
1
|
Octal and Hexadecimal Arithmetic
Octal and hexadecimal are pretty
much the same, except that you carry if the sum in a particular digit
exceeds either 8 or 16, respectively. Hexadecimal is more common, and
more interesting, so let's take an example of adding two hex numbers
together. While performing the operation, you will need to do conversions
of single-digit hex numbers to decimal and back again, but this isn't
too difficult.
This example is shown in Table 8,
which again should be read from right to left. We start by adding "8"
(decimal 8) to "A" (decimal 10) in the "ones" place. This yields a raw
sum of 18, from which we carry 16 as a "1" to the "16s" place and leave
a result of 2. We add this 1 to the "D" (value 13) and "E" (14 value)
of the "16s" place. This is a total of 28, leaving 12 ("C" in hexadecimal)
and we carry a 1 to the "256s" place. This continues until we are left
with a sum of 6DC2h.
|