 | Discussion Forum |  |
|
|
Floating PointNext Thread | Thread List | Previous Thread Start a Thread | Settings | Details | Message |
|---|
Read-Only Author Rodrigo Chacón Posted 9-Mar-2001 23:40 GMT Toolset C51 |  Floating Point Rodrigo Chacón How can I deny a number floating point without utilizat some mathematical operation?
How can I take the first 8 bits of the number floating point, those but significant (MSB) or the bit but significant of the number type floating point? | | Read-Only Author Jon Young Posted 11-Mar-2001 03:02 GMT Toolset C51 |  RE: Floating Point Jon Young Here is a routine to print the parts of a normalized float ( except for 0.0 or -0.0 ).
#include <stdio.h>
#include "AT89X55.H" // to define TI
typedef unsigned char BYTE;
typedef unsigned int WORD;
typedef unsigned long DWORD;
void PrintFloat( float TheFloat )
{
union
{
struct
{
float Float;
} Whole;
struct
{
//@Float+0
BYTE Exp1 :7; //bits 6-0
BYTE Sign :1; //bit 7
//@Float+1
BYTE Significand2 :7; //bits 6-0
BYTE Exp0 :1; //bits 7
//@Float+2
BYTE Significand1 :8; //bits 7-0
//@Float+3
BYTE Significand0 :8; //bits 7-0
} Parts;
} Float;
Float.Whole.Float = TheFloat;
printf( "Float = %#e\n", (double)TheFloat );
printf( "Sign = %#i\n", (int)Float.Parts.Sign );
printf( "Exp Base 2 = %#i\n" , ( (int)Float.Parts.Exp1<<1 | (int)Float.Parts.Exp0 ) - 127);
printf( "Mantissa Base 2 = %#lX\n" , 0x800000 | ( (DWORD)Float.Parts.Significand2 ) << 16
| ( (DWORD)Float.Parts.Significand1 ) << 8
| ( (DWORD)Float.Parts.Significand0 ) );
printf( "\n" );
}
void main(void)
{
TI = 1; //to get debugger to print to serial window
PrintFloat( -2.3456E10 );
PrintFloat( 0.0 ); //note!! 0.0 is all zeros plus a sign bit
while( 1 )
;
}
| | Read-Only Author Jon Young Posted 11-Mar-2001 03:10 GMT Toolset C51 |  RE: Floating Point Jon Young Does "Deny" = "Negate"?
Here is a fast negator.
*((BYTE*)&TheFloat) ^= 0x80;
| |
Next Thread | Thread List | Previous Thread Start a Thread | Settings |
|