Manning's Countdown to 2014
. Use discount code crdotd14 all month for 50% off every deal.
A friendly place for programming greenhorns!
Big Moose Saloon
Register / Login
Joined: Jun 08, 2009
Apr 08, 2011 18:40:28
>>What will be output by the following line of code?
Answer given was 12.
I read above question from link
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.
Jesper de Jong
Joined: Aug 16, 2005
Apr 12, 2011 15:21:51
When you write an integer literal starting with a 0 in Java, such as 010 in the code above, then the number is interpreted as an
number (base 8) instead of a normal, decimal number (base 10).
010 in octal = 8 in decimal (read about octal if you don't understand why).
The | operator is the bitwise OR operator.
So: 010 | 4 = 8 | 4, in binary this is: 1000 | 0100 = 1100, which is 12 in decimal.
Java Beginners FAQ
JavaRanch SCJP FAQ
The Java Tutorial
Java SE 7 API documentation
- My blog about Scala
subject: binary example
any one come up with a solution
Alice in Wonderland
Code to generate a Grid Test GUI
All times are in JavaRanch time: GMT-6 in summer, GMT-7 in winter
| Powered by
Copyright © 1998-2013