• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Bear Bibeault
  • Paul Clapham
  • Jeanne Boyarsky
  • Knute Snortum
Sheriffs:
  • Liutauras Vilda
  • Tim Cooke
  • Junilu Lacar
Saloon Keepers:
  • Ron McLeod
  • Stephan van Hulst
  • Tim Moores
  • Tim Holloway
  • Carey Brown
Bartenders:
  • Joe Ess
  • salvin francis
  • fred rosenberger

The OR opertor doubt

 
Ranch Hand
Posts: 481
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
What is the result of the following operation?

System.out.println(4 | 3);

1) 6
2) 0
3) 1
4) 7

here i dont know how to convert the 4 and 3 to binary ?

Please tell me the procedure for converting number to binary one?
I am weak in this one.
 
High Plains Drifter
Posts: 7292
Netbeans IDE VI Editor
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
The OR operation works on bits. If either bit of two in an OR operation is 1, then the result is 1, so:

4 = 100
3 = 011
--------
111

so the result must be 7 (or 4 + 2 + 1).
 
Karu Raj
Ranch Hand
Posts: 481
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
how did you convert the 4 to bits representation?
 
Ranch Hand
Posts: 243
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
To Convert any decimal number into binary
we can folow these steps

Lets Do it With An Exammple
decimal 22 into binary

make a table like this
1
2
4
8
16
32
64
..
..
..

if u wanna convert 22 look for the number or the number just smaller than this,so what i see that the table does not have 22 so the number next smaller than this is 16,write 1 in front of it

1
2
4
8
16--1
32
64
..
..
..

ok next step reduce 16 from the number 22,22-16=6
now we get the number 6 repeat the same procedure,we do not have 6 in the table but do have 4, write 1 in front of it

1
2
4 --1
8
16--1
32
64
..
..
..
now the repeat the same deduct 4 out of 6 ,6-4=2 you got 2 which is in the table,write 1 in front of it

1
2 --1
4 --1
8
16--1
32
64
..
..
..

now when u deduct you 0,2-2=0 so ur binary is complete
now to the remaining table numbers put a 0 in front of it


1 --0
2 --1
4 --1
8 --0
16--1
32
64
..
..
..
now just read the number from down to up,10110 here is your binary conversion
hope you understand this easily
 
Michael Ernest
High Plains Drifter
Posts: 7292
Netbeans IDE VI Editor
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
This might help too:

http://www.is.wayne.edu/olmt/binary/page3.htm
 
Ranch Hand
Posts: 579
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Mr. Michael
I wanna Know How 2s Complement Representation Works
thanks With Regards





Agrah Upadhyay
3rd Year
B.Tech
 
Karu Raj
Ranch Hand
Posts: 481
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thanks a lot very much

i am gratefull to all of you
 
Without subsidies, chem-ag food costs four times more than organic. Or this tiny ad:
Java file APIs (DOC, XLS, PDF, and many more)
https://products.aspose.com/total/java
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!