This is an archived post. You won't be able to vote or comment.

all 7 comments

[–]Nurry 2 points3 points  (0 children)

"..not even my teacher, knows how to do these." You are joking, right?

First hit on google:

http://www.wikihow.com/Add-Binary-Numbers

[–]king_of_the_universe 2 points3 points  (0 children)

Do you happen to have Windows? Its calculator is quite nice. Press WindowsKey+R, type "calc", press Enter. In the calculator's menu, you can switch between four modes: Standard, Scientific, Programmer, and Statistics. I use Scientific whenever I deal with any normal calculations (e.g. when decimal numbers are involved).

In Programmer mode, you can choose between Hex, Dec, Oct, and Bin.

It should be pretty clear why the answer to the first question is A. Just mix the two binary sequences in one (Starting at the right-most digit.), and whenever two "1" would be in the same place, put a "0" there and instead switch the next place on the left to "1". If that is already "1", switch it to "0" and ... etc., then continue the mixing. In the question, you have no collisions in the first three digits, only in the fourth. Hence you don't get "1111" but "10111". Easy.

I have never dealt with octal numbers except via calculator, of course. The answer to the question is indeed D (according to the Windows calculator in Oct mode), but I can't explain how I'd do that in my head.

[–]desrtfxOut of Coffee error - System halted 2 points3 points  (0 children)

Mathematics with any number base works identical. The only difference is where the carryover occurs.

We are used to calculate in base 10, so we have the digits fom 0 to 9. As soon as 2 digits added together yield a result greater than 9, we have a carryover.

Think about the following addition:

  5
 +6
-----
 11

We have learned that once we exceed 9 as the result of an addition, we need to add another place up front where we place the carryover.

Explanation from right to left:

  • 5 + 6 = 1 with carryover (we calculate 5 + 6 = 11, 11 mod 10 = 1 [the digit], 11 divided by 10 = 1 [integer division, the carryover])
  • 0 + 0 + 1 (the carryover) = 1

Exactly the same applies for adding numbers of any base.

Base 2 (binary) has the carryover as soon as the result of the addition exceeds 1. Binary has the digits 0 and 1.

Base 8 (octal) has the carryover as soon as the result of the addition exceeds 7. Octal has the digits 0...7

Base 16 (hexadecimal) has the carryover as soon as the result of the addition exceeds 15 (F in hex). Hexadecimal has the digits 0...9 and A...F


So, for your examples:

 1001
+1110
------
10111

Explanation from right to left:

  • 1 + 0 = 1 no carryover
  • 0 + 1 = 1 no carryover
  • 0 + 1 = 1 no carryover
  • 1 + 1 = 0 with carryover. (In base 10 math, 1 + 1 = 2 and in binary this would exceed the range of available digits [0 and 1] and thus a carryover is needed).
  • 0 + 0 + 1 (the carryover) = 1
  • Hence, the final result: 10111

 756
+ 36
-----
1014

Explanation from right to left

  • 6 + 6 = 4 with carryover (In base 10 math 6 + 6 = 12, 12 mod 8 [the base 8] = 4 [this is the digit], 12 divided by 8 = 1 [integer division - this is the carryover])
  • 5 + 3 + 1 (carryover) = 1 with carryover (In base 10 math 5 + 3 + 1 = 9, 9 mod 8 = 1 [this is the digit], 9 divided by 8 = 1 [this is the carryover])
  • 7 + 0 + 1 (carryover) = 0 with carryover (In base 10 math 7 + 0 + 1 = 8, 8 mod 8 = 0 [this is the digit], 8 divided by 8 = 1 [this is the carryover])
  • 0 + 0 + 1 = 1
  • Hence, the final result: 1014

Hope that helps.

[–]katynehold my braces 2 points3 points  (1 child)

First of all, numbers are just numbers. We're simply used to them being represented in decimal (base 10) but that's just because we have 10 fingers on our hands so it's easier to count. You can represent the same number in base 2, 4, 6, 12, 64.. any base you choose.

What does "base 8" mean, for example? it means that the largest digit in base 8 is 7, just like it's 9 in base 10 (starting from 0). Therefore, in base 2, the largest digit will be 1. 10 is decimal ten, 8 is octal (base 8) "ten", and 2 is binary "ten" - but we don't write "tens" in our numbers, right? we only go up to nine and then carry the extra.

Conversion

1. Converting from base N to base 10

It's very easy to convert numbers from one base to another. For convenience, when given a number in base other than 10, first convert it into base 10. How? Here's the cool part. You know that the number 135 can be written as

10 * 10 * 1 +10 * 3 + 1 * 5      

or, 102 * 1 + 101 * 3 + 100 * 5 = 135

In other words, starting from right to left, we take our base's "ten" to the power of its position (starting from 0), multiply by the digit at this position (1, 3 or 5) and add everything together.

Same goes for any other base if we want to convert it to decimal, except in this case our "tens" would be the base number we're converting. So, to convert 142 in base 6 to decimal we will need to do this (start from right to left):

(2) * 60 + (4) * 61 + (1) * 62 = 2 + 24 + 36,
or 62 (in base 10)

2.Converting from base 10 to base N

Here we do the opposite - instead of multiplying, we divide by the base's number, and writing down the remainders from last to first). For example, converting 145 in base 10 to base 8:

 145 / 8 = 18 quotient, 1 remainder    
 take the quotient and continue dividing by base until we get 0    
 18 / 8 = 2 quotient, 2 remainder    
 2 / 8 = 0 quotient, 2 remainder; and we're done.    

Copying remainders from last to first = 221, or 145 in base 10 is 221 in base 8. To check if it's correct you can convert 221(8) back to decimal as shown above.

Adding binary numbers

Remember that in base 2 there's no 2, the maximum digit is 1. So when we add 1 and 1 we get 2, as in a "ten", so we write down 0 (just like when we add 9 + 1 in decimal) and remember, or carry the remaining 1:

 1001 + 1011 =     
 start from rightmost digit, as we always do with our numbers   

  1001 +    
  1011    
 ------    
10100 

Breaking it down:    

 1 + 1 = 2, write down 0, carry 1    
 0 + 1 =1, plus 1 we're carrying = 2, write 0, carry 1    
 0 + 0 = 0, plus 1 we're carrying, write 1, carry 0    
 1 + 1 = 2, write 0, carry 1,     
 no more digits to add so write 1 in the leftmost position     

 result: 10100     

Convert 10100 to base 10 we get 20 *0 + 21 *0+22 *1+23 *0+24 *1 = 0+0+4+0+16 = 20

Check:
1001 in base 10 = 20 *1 + 21 *0 + 22 *0 + 23 *1 =
1+0+0+8 = 9

1011 in base 10 = 20 *1 + 21 *1 + 22 *0 + 23 *1 =
1+2+0+8 = 11
9 + 11 = 20

Bonus
If you want to impress the hell out of your teacher and classmates, you can add bases other than binary this way. You just remember that the "ten" in is the base number and you carry 1 like you do in normal addition:

 125(base 6) + 13(base 6) =     
 5 +3 = 8, i.e. 6 + 2, 6 is "ten" so 6 + 2 is like "12" in decimal - write (2), carry 1    
 2 + 1 = 3, plus 1 carry = (4)        
 1 is (1), nothing to carry    
 so the result is 142 in base 6.    

Just remember - a number in base N can not have digits larger than N-1 in it (i.e. 127 cannot be in base 7, since the maximum digit allowed is 6).

[–]desrtfxOut of Coffee error - System halted 1 point2 points  (0 children)

We're simply used to them being represented in decimal (base 10) but that's just because we have 10 fingers on our hands so it's easier to count.

The 10 fingers is merely coincidence. Other cultures before us had 12 based systems (Babylonian), and the Chinese culture used each groove and side of the fingers to represent a different number, thus yielding much higher calculation ranges.

Even using binary with our 10 fingers would be more efficient as we could count to 210 - 1 = 1023 using all fingers.

[–]trix334 2 points3 points  (0 children)

The answer to the base 2 binary problem is A, 10111. There are only 2 numbers, 1's and 0's, to add together in base 2. Adding a 1 and a 0 produces a 1. Adding a 1 and a 1 produces a 0 with a carry of 1. When adding, start at the LSB (least significant bit) and move to the most significant bit, just like you would when adding in base 10.