Results 1 to 5 of 5

Thread: Addition of Binary

  1. #1

    Thread Starter
    Lively Member
    Join Date
    May 1999
    Posts
    89

    Post

    Does anyone know how to add binary numbers and if you have any code that would be awesome. for example i need to add binarry numbers like so:
    01000011.11011101.10100111.11000000
    11111111.10000000.00000000.00000000

    but i know a 1 and 1 cannot be 2 so is a 1 and 1 10 or 01, so as you can see im just making myself confused. Any help would be greatly apprecaited.

    Regards,

    Scott

  2. #2
    Hyperactive Member
    Join Date
    Feb 2000
    Posts
    284

    Post

    Binary addition
    1
    +1
    _______
    10

    10
    +11
    _______
    101

    It's just like decimal really except the numbers only go up to 1, so counting would be
    decimal binary
    0 0
    1 1
    2 10
    3 11
    4 100
    5 101
    6 110
    7 111
    8 1000
    9 1001
    10 1010

  3. #3
    Guest

    Post

    0 0
    1 1
    2 01
    3 11
    4 001
    5 101
    6 011
    7 111
    8 0001
    9 1001
    10 0101

    I think Bigley got it backwards.



    ------------------
    Boothman
    There is a war out there, and it is about who controls the information, it's all about the information.


  4. #4
    Hyperactive Member Juan Carlos Rey's Avatar
    Join Date
    Aug 1999
    Location
    Mendoza, Argentina
    Posts
    301

    Post

    Hi, scottr.

    There are two ways:

    1- Make a function to convert your binaries into decimal, add the decimals together, re-convert to binary.

    2- Use the very simple addition rule:

    0 + 0 = 0
    0 + 1 = 1
    1 + 0 = 1
    1 + 1 = 0 plus a "carry"

    That "carry" works just like in decimal, shift it one place to the left and add it to the digits that were in that place using the same rule.

    HTH

    P.S. Boothman_7: It seems your hand is shaking a bit (on the SubmitNow key, hahaha)
    but Bigley is right: 10 = 1010; your 0101 is actually a 5 (0101 = 101 - zeros at left don't count)


    [This message has been edited by Juan Carlos Rey (edited 02-19-2000).]

  5. #5

    Thread Starter
    Lively Member
    Join Date
    May 1999
    Posts
    89

    Post Binary Addition

    Thanks alot for all the input guys. What i ended up doing was converting it to int and doing the addition that way.

    Regards,

    Scott

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width