??? 06/30/06 07:58 Read: times |
#119403 - Float to Byte Responding to: ???'s previous message |
Hello Satish,
Here is a piece of code cut from my commercial product. Hope this helps. //============================================================== //This usually goes into header file //============================================================== union FloatToByte { float FloatData; Byte FToB[4]; }; //============================================================== //This is usually placed on top of the source file //============================================================== union FloatToByte EeFloat; //============================================================== void WriteEepromFloat(float FourDigitNumber, Word Address) { EeFloat.FloatData=FourDigitNumber; WriteEepromByte(EeFloat.FToB[0],Address); WriteEepromByte(EeFloat.FToB[1],Address+1); WriteEepromByte(EeFloat.FToB[2],Address+2); WriteEepromByte(EeFloat.FToB[3],Address+3); } //============================================================== float ReadEepromFloat(Word Address) { EeFloat.FToB[0]=ReadEepromByte(Address); EeFloat.FToB[1]=ReadEepromByte(Address+1); EeFloat.FToB[2]=ReadEepromByte(Address+2); EeFloat.FToB[3]=ReadEepromByte(Address+3); return(EeFloat.FloatData); } //============================================================== Regards, John. |
Topic | Author | Date |
Integarting and disintgration of float | 01/01/70 00:00 | |
Float to Byte | 01/01/70 00:00 | |
use a union? | 01/01/70 00:00 | |
Use a union, but ... | 01/01/70 00:00 | |
Might not matter... | 01/01/70 00:00 | |
Unwarranted assuption | 01/01/70 00:00 | |
thanks a lot | 01/01/70 00:00 | |
you can also try.... | 01/01/70 00:00 | |
again![]() | 01/01/70 00:00 |