floating point - Converting float to hex results in more digits than expected in C#? -
i'm going convert c# floating point number 2 bytes, instance have number 12.4544 , should 0x4147, or 0x41474539, i've used bitconverter.doubletoint64, gives me weird, how can 0x4147?
i'm creating modbus slave, , should send each float number 2 bytes
thanks
edit: oh dear oh dear, missed this, short answer:
use bitconverter.getbytes
, pass float, shown here.
the long answer:
bitconverter doesn't support single precision floats, double
s. you'll have create c# "union", so:
[structlayout(layoutkind.explicit)] class floater { [fieldoffset(0)] public float thefloat; [fieldoffset(0)] public int theint; }
put float in thefloat
, @ theint
Comments
Post a Comment