This week's book giveaway is in the Servlets forum.
We're giving away four copies of Murach's Java Servlets and JSP and have Joel Murach on-line!
See this thread for details.
The moose likes Programmer Certification (SCJP/OCPJP) and the fly likes adding bits Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login

Win a copy of Murach's Java Servlets and JSP this week in the Servlets forum!
JavaRanch » Java Forums » Certification » Programmer Certification (SCJP/OCPJP)
Bookmark "adding bits" Watch "adding bits" New topic

adding bits

amrit singh
Ranch Hand

Joined: Nov 03, 2000
Posts: 42
could ne one pls tell me
how to add
and how to handle carry over
anil bisht
Ranch Hand

Joined: Nov 04, 2000
Posts: 81
we will try this
0+0 = 0
1+1 = 2 but its binary so u have to write 1+1 = 10( binary)
so 0 is to be placed there and 1 is the carry
now add 0 + 0 + 1 = 1
so the answer is
so ur answer is 101010100
but if u have the size of 8 bits the last bit will be lost
and u will get 1010100
bill bozeman
Ranch Hand

Joined: Jun 30, 2000
Posts: 1070
For this I usually find it easier to convert them to decimal, then do the addition, and then convert them back to binary. So you are adding 170 + 170 = 340, then take 340 to binary and you get 101010100.
I agree. Here's the link:
subject: adding bits
Similar Threads
Making a binary to decimal converter
(Not Safe for work)T- shirt Slogans and messages
2's complement
byte b=127; b++=??
Could someone explain "|=" and "&=" assignment operations?