Binary Numbers

• January 6th, 2011, 01:51 PM
Bido
Binary Numbers
I did some exercises. It's binary numbers.
But the problem is that i don't know if it's
right. Maybe there are some mistakes and it
would be perfect if somebody could look through and

b. Make the following calculations with 8 bit numbers. Show carries and indicate whether an overflow occurred.

00101100
+ 00011101

01100010
+00100110

3A
+FB

bold = overflow

first: 01001001 overflow

second: 10001000 overflow

third: A+B = 15; 3+F+1=13 => 1354 => 30910

d. In a base 4 number system, we have the digits 0,1,2 and 3. Convert the base-4 number 323104 to decimal, octal and hex. How many bits do we need to store the value in memory on a digital computer ( hint: convert to binary)
0*1+1*4+3*16+2*64+3*256=948
94810 = 11101101002
10 digits = we need 10 bits to store it
(here i didn't manage to do octal and hex :( )
• January 6th, 2011, 02:54 PM
helloworld922
Re: Binary Numbers
Quote:

bold = overflow
That's not an over-flow, that's actually a carry. An overflow is when the number of bits required to store the resulting number is greater than the number of bits you have available (8).

Quote:

third: A+B = 15; 3+F+1=13 => 1354
I think you meant 13516? That would be the correct answer.

For the last one, if you have the binary number simply use that to convert the number to octal/hex.

Here's a trick for converting between binary and hex:
Every hex digit can be represented with 4 binary digits. So you only need to memorize the 16 binary digit combinations (or count up/down in binary) to get the matching hex digit:
(I'm using the Java hex notation, but the numbers on the left are binary)
0000 = 0x0
0001 = 0x1
0010 = 0x2
0011 = 0x3
0100 = 0x4
0101 = 0x5
0110 = 0x6
0111 = 0x7
1000 = 0x8
1001 = 0x9
1010 = 0xA
1011 = 0xB
1100 = 0xC
1101 = 0xD
1110 = 0xE
1111 = 0xF

Now to use this trick, simply take your binary number and group it into 4's and use that table to match your digits.

So,
1000 1010 0100 0101 0101 0101 0011 1001 1111 = 0x8A45559F

Converting to octals has the same trick: use groupings of 3.
100 010 100 100 010 101 010 101 001 110 011 111 = 4244252516378

And how about base 4? If you guessed groupings of 2, you'd be correct.

Going backwards is equally as easy.

Unfortunately, there's no easy way to convert from 2 to decimal (well, not that I know of). You must simply convert using the basic "algorithm" for base conversion.