View previous topic :: View next topic |
Author |
Message |
nilsener Guest
|
Sign Bit in a float |
Posted: Wed Dec 11, 2002 4:22 am |
|
|
Dear,
where to find the sign bit in a float variable ?
Thanks for helping
regards nilsener
___________________________
This message was ported from CCS's old forum
Original Post ID: 9965 |
|
|
R.J.Hamlett Guest
|
Re: Sign Bit in a float |
Posted: Wed Dec 11, 2002 5:38 am |
|
|
:=Dear,
:=
:=where to find the sign bit in a float variable ?
:=
:=Thanks for helping
:=
:=regards nilsener
It is the top bit of the third byte. Basically the low three bytes contain an integer, with the fourth byte containing the binary exponent. The integer is 23bits, plus the sign bit.
So:
union {
int8 b[4];
float f;
} value;
value.f=10000.0;
if (value.b[2] & 128) {
//This will test as true if the float is negative
}
Best Wishes
___________________________
This message was ported from CCS's old forum
Original Post ID: 9968 |
|
|
nilsener Guest
|
Re: Sign Bit in a float |
Posted: Wed Dec 11, 2002 9:56 am |
|
|
Thanks :)
:=:=Dear,
:=:=
:=:=where to find the sign bit in a float variable ?
:=:=
:=:=Thanks for helping
:=:=
:=:=regards nilsener
:=It is the top bit of the third byte. Basically the low three bytes contain an integer, with the fourth byte containing the binary exponent. The integer is 23bits, plus the sign bit.
:=So:
:=union {
:= int8 b[4];
:= float f;
:=} value;
:=
:=value.f=10000.0;
:=
:=if (value.b[2] & 128) {
:= //This will test as true if the float is negative
:=
:=}
:=
:=Best Wishes
___________________________
This message was ported from CCS's old forum
Original Post ID: 9976 |
|
|
|