Skip to content

Instantly share code, notes, and snippets.

@TheB1ackSheep
Created February 8, 2014 13:35
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save TheB1ackSheep/8883810 to your computer and use it in GitHub Desktop.
Save TheB1ackSheep/8883810 to your computer and use it in GitHub Desktop.
using System;
using System.Collections.Generic;
using System.Linq;
using System.Runtime.InteropServices;
using System.Text;
namespace ConsoleApplication
{
class Program
{
static void Main(string[] args)
{
unsafe
{
float _f1, _f2;
_f1 = -130.05f;
_f2 = 130.05f;
float* _f1Addr = &_f1;
float* _f2Addr = &_f2;
byte[] _f1Val = new byte[4];
byte[] _f2Val = new byte[4];
Marshal.Copy((IntPtr)(float*)&_f1, _f1Val, 0, _f1Val.Length);
Marshal.Copy((IntPtr)(float*)&_f2, _f2Val, 0, _f2Val.Length);
String _f1Str = "", _f2Str = "";
for (int i = _f1Val.Length-1; i >= 0;i-- )
_f1Str += Convert.ToString(_f1Val[i], 2).PadLeft(8, '0');
for (int i = _f2Val.Length - 1; i >= 0; i--)
_f2Str += Convert.ToString(_f2Val[i], 2).PadLeft(8, '0');
System.Console.WriteLine("The value of _f1 is {0}",_f1);
System.Console.WriteLine("The address of _f1 is {0:X08}", (int)&_f1);
System.Console.WriteLine("The bin of _f1 is {0}\n", _f1Str);
System.Console.WriteLine("The value of _f2 is {0}", _f2);
System.Console.WriteLine("The address of _f2 is {0:X08}", (int)&_f2);
System.Console.WriteLine("The bin of _f2 is {0}", _f2Str);
System.Console.ReadKey();
}
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment