This week's book giveaways are in the Jython/Python and Object-Oriented programming forums.
We're giving away four copies each of Machine Learning for Business: Using Amazon SageMaker and Jupyter and Object Design Style Guide and have the authors on-line!
See this thread and this one for details.
Win a copy of Machine Learning for Business: Using Amazon SageMaker and JupyterE this week in the Jython/Python forum
or Object Design Style Guide in the Object-Oriented programming forum!
  • 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

Bit shift Mock Exam

 
Greenhorn
Posts: 20
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi guys,
I'm a bit confused about this question that appears on Marcus Greene's mock exam:
Question 47)
What will be output by the following line of code?
System.out.println(010|4);
1) 14
2) 0
3) 6
4) 12
The answer given is 12, because "the octal notaction which means that the leading letter zero (not the letter O)) means that the first 1 indicates the number contains one eight and nothing else".
I understand how you arrive at 12 from this conclusion, but I can't get how you're supposed to know that 010 is octal 8 and not binary 2 or something.. am i just incredibly dumb? can someone explain this please?
Thanks guys!
P.S. apologies if this question has already been answered somewhere else on this board but I couldnt find anything from searching - thanks!
 
Ranch Hand
Posts: 73
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
In java any numeric literal starting with a 0 is considered as octal and nothing else. So it is considered as octal and 010 octal is 8 decimal. I also have seen traps in some questions which will give a literal as 0739. In this case literal 0739 is wrong since you cannot have digit with more than 7 in octal.
Hope this helps --
Hari Gangadharan
 
Binkie Hayes
Greenhorn
Posts: 20
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thanks Hari! I understand this now!
thanks for taking the time to answer
:-)
 
I am not a spy. Definitely. Definitely not a spy. Not me. No way. But 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!