Link to home
Start Free TrialLog in
Avatar of gudii9
gudii9Flag for United States of America

asked on

binary example

>>What will be output by the following line of code?

System.out.println(010|4);

1) 14
2) 0
3) 6
4) 12

Answer given was 12.

 
I read above question from link
http://www.jchq.net/certkey/0503certkey.htm
i did not understand how 12 is answer and how octal is related here.



Any ideas, resources,sample code,links,  highly appreciated. thanks in advance.
Avatar of for_yan
for_yan
Flag of United States of America image


010 is octal ten as it starts with zero, means it is decimal 8 or binary 1000

4 is binary 100

now when you make bitwise or 1000 with 100 you end up with 1100 which will be 8 + 4 = 12

SOLUTION
Avatar of Am P
Am P
Flag of India image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of gudii9

ASKER

>>4 is binary 100
How to know the number orignally in which mode like octal, binary, decimal, Hex etc. Then
how we know we have to convert to binary before adding when there are 10 different modes like Hex, Octal etc all. please advise
ASKER CERTIFIED SOLUTION
Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial