• Post Reply Bookmark Topic Watch Topic
  • New Topic

java.lang.Float intBitsToFloat  RSS feed

 
Ramya Iyer
Ranch Hand
Posts: 66
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi,

As per the method definition provided in sdk,

In all other cases, let s, e, and m be three values that can be computed from the argument:

int s = ((bits >> 31) == 0) ? 1 : -1;
int e = ((bits >> 23) & 0xff);
int m = (e == 0) ?
(bits & 0x7fffff) << 1 :
(bits & 0x7fffff) | 0x800000;
Then the floating-point result equals the value of the mathematical expression s�m�2(e-150).




Output is
s: 1 e: 0 m: 128
9.0E-44

I am able to understand the value of s, e, m. But I cannot understand how f1 is 9.0 e-44. Can anyone explain?
 
Barry Gaunt
Ranch Hand
Posts: 7729
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
This question is out of scope for SCJP 1.4/5.0, moving to Java In General (intermediate)
 
Grant Gainey
Ranch Hand
Posts: 65
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Integer constants with a leading zero are octal. Change your 0...0100" to plain "100" and you'll get the value I think you're expecting (1.4E-43).

BTW - If you haven't already found it, here's a good place to go to check your work when you're doing this kind of stuff:

IEEE754 Conversion

Grant

[Eited to remove extraneous newline]
[ October 16, 2005: Message edited by: G Gainey ]
 
Campbell Ritchie
Marshal
Posts: 56518
172
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
You can't use an Integer object, but how about this?


That ought to come out as bits being 4.

See the Integer class and the overloaded parseInt(String s, int radix) method.

CR
[ October 17, 2005: Message edited by: Campbell Ritchie ]
 
Grant Gainey
Ranch Hand
Posts: 65
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Ummm...well, you could do it that way. Hadn't ocurred to me that the OP was just specifying the bit-pattern. I'd probably just do it using hex, in that case:

Grant
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!