• 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

To solve Don's example

 
Ranch Hand
Posts: 76
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi All,

Please help me how to solve this question.I have difficulty in converting hex form to decimal and then do shift opeartion.Is it not time consuming.?
----------
Prashant
[ Jess added UBB [code] tags to preserve whitespace, check 'em out! ]
[ January 08, 2003: Message edited by: Jessica Sant ]
 
Ranch Hand
Posts: 2120
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
There is no need to convert between hex to decimal, because the shift operations should be performed in a number system in which the bits are visualized, that is hex or binary. The variable to shift is already hex.
int i1 = 0xffffffff;
int i2 = i1 << 1;
ffff fffe
int i3 = i1 >> 1;
ffff ffff
int i4 = i1 >>> 1;
7fff ffff
Please read Cat and Mouse games with bits to understand the bit operators in Java.
This is from the Java Tutorial Shift and logical operators
Also make sure to learn about hexadecimal, binary and octal number system. They are a bit basic thing for this forum.
 
Sheriff
Posts: 4313
Android IntelliJ IDE Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Originally posted by Prashant Neginahal:
Please help me how to solve this question.I have difficulty in converting hex form to decimal and then do shift opeartion.Is it not time consuming.?


Actually -- don't you need to go from hex to binary? shift it -- then back to hex?
Converting Hex to Binary is actually quite easy -- each hex digit goes to a 4 digit binary number:
i1 = 0xffffffff =
1111 1111 1111 1111 1111 1111 1111 1111
i2 = i1 << 1;
1111 1111 1111 1111 1111 1111 1111 1110
= 0xfffffffe
i3 = i1 >> 1;
1111 1111 1111 1111 1111 1111 1111 1111
= 0xffffffff
i4 = i1 >>> 1;
0111 1111 1111 1111 1111 1111 1111 1111
= 0x7fffffff
 
Ranch Hand
Posts: 1865
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Thank you Jose and Jessica.
Prashant, I used Hex in that question because any other number system would have made the question more difficult. Hexadecimal was developed to make it easier to move data in and out of computers. Learning to use hexadecimal certainly makes a programers life easier.
Hex is a programmers best friend.
 
Don't get me started about those stupid light bulbs.
reply
    Bookmark Topic Watch Topic
  • New Topic