Help coderanch get a
new server
by contributing to the fundraiser
  • 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
  • Ron McLeod
  • Paul Clapham
  • Devaka Cooray
  • Liutauras Vilda
Sheriffs:
  • Jeanne Boyarsky
  • paul wheaton
  • Henry Wong
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Tim Moores
  • Carey Brown
  • Mikalai Zaikin
Bartenders:
  • Lou Hamers
  • Piet Souris
  • Frits Walraven

store 0xFFFFFFFF

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

I need to stored 0xFFFFFFFF as an integer.
I tried using long without success.

Please help.
 
Ranch Hand
Posts: 229
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Ok, so why don't you store it as an integer. It does not exceed the allowed value for an int.
 
Ranch Hand
Posts: 410
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Well, that depends. Remember that although ints are 32 bits (4 bytes, like the number above), they are always signed so we only have the range of approximately +/- 2^31
 
Rancher
Posts: 43081
77
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
It is possible to store the bit pattern consisting of 32 ones as an int, but Java will interpret that to mean "-1", because all numbers having the most significant bit set are negative.


I tried using long without success.



What does this mean? Have you tried:

long num = 0xffffffffl;

(That's a leading zero before the x, and a trailing lowercase letter L).
[ August 12, 2005: Message edited by: Ulf Dittmer ]
 
Rancher
Posts: 5013
38
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Another way to get what java might consider as negatively signed data into an int without the spreading of the sign bit is by ANDing it with the mask: 0xFF to insure the high order bits are set to 0.
 
Ranch Hand
Posts: 657
Spring VI Editor Clojure
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

(That's a leading zero before the x, and a trailing lowercase letter L).

It doesn't have to be lowercase; in fact it's preferable to use the uppercase "L" so you don't confuse it with the number "1"; I believe that's one of Bloch's puzzlers...
 
Steve Morrow
Ranch Hand
Posts: 657
Spring VI Editor Clojure
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Originally posted by Norm Radder:
Another way to get what java might consider as negatively signed data into an int without the spreading of the sign bit is by ANDing it with the mask: 0xFF to insure the high order bits are set to 0.


Maybe I'm not understanding what you're proposing, but that will mask off everything but the 8 lowest bits. Is that your intended behavior? How is that getting negatively signed data into an int without "spreading the sign bit"?
 
Ranch Hand
Posts: 3061
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Originally posted by Mahesh Bogadi:
Hi All,

I need to stored 0xFFFFFFFF as an integer.
I tried using long without success.

Please help.



int x = 0xFFFFFFFF;

What's wrong with this? As noted above, Java will interpret this as -1 if you simply use it as an int, but if your are doing bit manipulations why does this matter? Maybe I don't understand your question. If you can explain what you have tried and why it didn't seem to work, we can help a lot more easily. At the moment all we can do is guess what your problem is, but that isn't a very efficient way of answering your question.

Layne
 
reply
    Bookmark Topic Watch Topic
  • New Topic