-2

We have something like:

float f = 1234.5678F;

Let's pretend the binary representation of this is 0x1234ABCD. How can I get the value 305441741 (==0x1234ABCD) from f?

Joseph Nields
  • 5,527
  • 2
  • 32
  • 48

1 Answers1

2

BitConverter class should help you.

BitConverter.GetBytes

Something like this:

float f = 1234.5678F;
var bytes = BitConverter.GetBytes(f);
var result = string.Format("0x{0:x}{1:x}{2:x}{3:x}", bytes[0], bytes[1], bytes[2], bytes[3]);
Ondra
  • 1,619
  • 13
  • 27