• 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 Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

How to solve this ?

 
Ranch Hand
Posts: 32
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
i = ox7A5;
i>>=3;


what is value of i after this statement ?
 
Ranch Hand
Posts: 1032
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Do you know how to represent numbers from different bases in binary form? If you are taking SCJP 6, don't even worry about this, since I don't think the bit operators are in the exam.

In any case, I think this is how it goes:

i = ox7A5;
i>>=3;

7A5 in hexadecimal is (each hexadecimal number is represented in 4 bits, and you pad with 0s to the left to make the total of 32 bits that an int variable has, assuming i is an int variable):
0000 0000 0000 0000 0000 0111 1010 0101
Then, you shift 3 positions to the right without sign extension:

0000 0000 0000 0000 0000 0000 1111 0100

This, in hexadecimal, is F4. So i will become 0xF4, which is 244 in decimal.
 
Sheriff
Posts: 11343
Mac Safari Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
It would help to know how you were approaching this, so that we know how to provide better help. For example, do you know what 0x7A5 represents (note that the leading character should be a zero -- not a lowercase 'o')? And do you know what the >> operator does (and recognize that it's combined with the assignment operator here)?
 
A Agr
Ranch Hand
Posts: 32
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
hey I got it. I know conversions and shift operator too..

what wrong I was doing is ,I was converting hexadecimal to decimal rather than converting it directly to binaryb...

Thanks..
 
Java Cowboy
Posts: 16084
88
Android Scala IntelliJ IDE Spring Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

A Agr wrote:i = ox7A5;


This is not going to compile. You need to use "0x" (zero, x), not lower-case letter o, x for hexadecimal numbers.
 
Don't get me started about those stupid light bulbs.
reply
    Bookmark Topic Watch Topic
  • New Topic