Google
 
Site navigation: [ Home | Theory | Java | About ]

Binary & hexadecimal addition

4.1.1
Calculate in binary and hexdadecimal

 

Binary addition has four basic rules, the first 3 of which are pretty obvious:

0 + 0 = 0
0 + 1 = 1
1 + 0 = 1
1 + 1 = 0 carry 1.

Example 1:

0

1

0

0

1

1

0

1

+

0

0

0

0

0

1

1

0

carry ->

1

1

result ->

0

1

0

1

0

0

1

1

If you are adding in columns and you have to do 1 + 1 + carry then the result will be 1 carry 1 to the next col umn:

0

0

0

0

1

1

1

1

+

0

0

0

0

0

1

1

0

carry ->

1

1

1

result ->

0

0

0

1

0

1

0

1

Confirm that these additions are correct by converting the numbers to base 10.

Try these:

1

0

0

0

1

0

1

0

+

0

0

0

1

1

1

0

1

carry ->

result ->

1

1

0

0

1

1

1

1

+

0

0

1

0

0

0

1

1

carry ->

result ->

1

1

1

1

0

0

0

1

+

0

0

0

0

1

1

1

1

carry ->

result ->

What happened in the last example?

This is known as "overflow ".

Imagine now that the three examples given above are in two's complement form (the last value is the same magnitude but negative - ie -128).

Convert to decimal and see what the examples tell you. Comment on the last example again.

We conclude that when subtracting two numbers by adding a two's complement form positive number to a two's complement form negative number, that any overflow beyond the MSB can be ignored . This is not true, of course, for addition.

Consider two hexadecimal numbers:

0

0

1

A

0

2

0

9

carry ->

1

result ->

0

2

2

3

When we add the first column 9 + A we clearly go beyond F - the largest hex symbol we can have. I got three by starting my left-hand thumb at A and then counting round 9 fingers (not forgetting 0) to get the 3. Then of course we need to carry 1 (place value 16) to the next column.

This is a bit tricky if you have to add, say C and D - you need more than 10 fingers (unless you can "wrap around" of course.

The easiest way (I find) is to write down the numbers on a piece of paper (which you can do in the exam - remembering you won't have a calculator with you), and count around:

For example to add C to D:

0 1 2 3 4 5 6 7 8 9 A B C D E F
                             start
                              here

Now, count around 1 on D, 2 on E, 3 on F, 4 on 0 and so on, until you count to D; you should end up on 9.

0

0

0

C

0

0

0

D

carry ->

1

result ->

0

0

1

9

Try these - no calculators allowed! (Except for your poor old teacher, that is):

0

2

9

A

0

2

0

B

carry ->

result ->

0

F

9

0

0

2

9

D

carry ->

result ->

Back to top

related: [ Topic 4 home | next: real numbers ]

The IB Exam does not allow calculators so you will have to learn these the way you did maths in elementary school.


 
The site is partly financed by advertising revenue, partly by online teaching activities and partly by donations. If you or your organisation feel these resouces have been useful to you, please consider a donation, $9.95 is suggested. Please report any issues with the site, such as broken links, via the feedback page, thanks.

Questions or problems related to this web site should be addressed to Richard Jones who asserts his right to be identified as the author and owner of these materials - unless otherwise indicated. Please feel free to use the material presented here and to create links to it for non-commercial purposes; an acknowledgement of the source is required by the Creative Commons licence. Use of materials from this site is conditional upon your having read the additional terms of use on the about page and the Creative Commons Licence. View privacy policy.

Creative Commons License


This work is licensed under a Creative Commons Attribution-NonCommercial-ShareAlike 2.5 License. © 2001 - 2009 Richard Jones, PO BOX 246, Cambridge, New Zealand;
This page was last modified: October 28, 2013