Welcome to the Java Programming Forums

The professional, friendly Java community. 21,500 members and growing!

The Java Programming Forums are a community of Java programmers from all around the World. Our members have a wide range of skills and they all have one thing in common: A passion to learn and code Java. We invite beginner Java programmers right through to Java professionals to post here and share your knowledge. Become a part of the community, help others, expand your knowledge of Java and enjoy talking with like minded people. Registration is quick and best of all free. We look forward to meeting you.


Members have full access to the forums. Advertisements are removed for registered users.

Results 1 to 2 of 2

Thread: Binary Numbers

  1. #1
    Junior Member
    Join Date
    Jan 2011
    Thanked 0 Times in 0 Posts

    Default Binary Numbers

    Need your help! Please.
    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
    correct them. Thanks in advance.

    Here are my answers:

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

    + 00011101



    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)
    94810 = 11101101002
    10 digits = we need 10 bits to store it
    (here i didn't manage to do octal and hex )
    Last edited by Bido; January 6th, 2011 at 02:56 PM.

  2. #2
    Super Moderator helloworld922's Avatar
    Join Date
    Jun 2009
    Thanked 619 Times in 561 Posts
    Blog Entries

    Default Re: Binary Numbers

    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).

    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.

    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.
    Last edited by helloworld922; January 6th, 2011 at 03:56 PM.

  3. The Following User Says Thank You to helloworld922 For This Useful Post:

    Bido (January 7th, 2011)

Similar Threads

  1. 8 bit binary to ascii
    By grahamb314 in forum Algorithms & Recursion
    Replies: 5
    Last Post: May 6th, 2011, 05:22 AM
  2. need help with binary tree
    By vash0047 in forum Java Theory & Questions
    Replies: 5
    Last Post: July 12th, 2010, 08:23 AM
  3. How to write 2 dimensional array of float numbers to binary file?
    By Ghuynh in forum File I/O & Other I/O Streams
    Replies: 4
    Last Post: June 17th, 2010, 04:26 PM
  4. binary conversion..
    By chronoz13 in forum Java Theory & Questions
    Replies: 8
    Last Post: September 16th, 2009, 10:47 AM
  5. How to convert float and double data types to binary?
    By rosh72851 in forum Java Theory & Questions
    Replies: 1
    Last Post: October 7th, 2008, 10:45 PM

Tags for this Thread