aspose file tools
The moose likes Beginning Java and the fly likes bit twiddling with floating point primitives Big Moose Saloon
  Search | Java FAQ | Recent Topics
Register / Login


JavaRanch » Java Forums » Java » Beginning Java
Reply Bookmark "bit twiddling with floating point primitives" Watch "bit twiddling with floating point primitives" New topic
Author

bit twiddling with floating point primitives

Leroy J Brown
Ranch Hand

Joined: Dec 02, 2007
Posts: 71
Is there a reason that bit-shifts and bitwise twiddling is not allowed on doubles and floats?
Henry Wong
author
Sheriff

Joined: Sep 28, 2004
Posts: 16815
    
  19

Originally posted by Tristan Rouse:
Is there a reason that bit-shifts and bitwise twiddling is not allowed on doubles and floats?



Actually, you can... it just isn't very useful to do so.

If you want, you can get the raw bits, using the Double class, and shift them (you can also put the raw bits back with the Double class).... but why?

Floating point is stored in an IEEE format, which is really really complicated -- storing the mantissa and exponent together, along with normalization, and special patterns for specific values (like infinity). Shifting these values just doesn't make sense.

Henry


Books: Java Threads, 3rd Edition, Jini in a Nutshell, and Java Gems (contributor)
fred rosenberger
lowercase baba
Bartender

Joined: Oct 02, 2003
Posts: 10043
    
    6

it would sort of like shifting all the letters in a sentence over one word.

i twoul dsor to flik eshiftin gal lth eletter si n asentenc eove ron ewor.

you can do it, but why? the results are more or less meaningless.


Never ascribe to malice that which can be adequately explained by stupidity.
Henry Wong
author
Sheriff

Joined: Sep 28, 2004
Posts: 16815
    
  19

Gagree. Dbu twit hfloatin gpoint, si ti seve nmor emeaningles. Swit hcharacter, sa tleas tther ei s achanc et ounderstan dwha ti sgoin go. Nwit hth EIEE efloatin gpoin tstandar, di ti sjus tto ocomplicate dt ounderstan, deve nwithou tth ebi tshiftin.

Enryh
Campbell Ritchie
Sheriff

Joined: Oct 13, 2005
Posts: 32833
    
    4
link


 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: bit twiddling with floating point primitives
 
Similar Threads
SCJP 1.5 books
>>> Shift Operator Doubt
Manipulating Hex Integers
What is NOT included in SCJP 1.5?
Bit Manipulation Tips?