- Home /
Question by
typane · Aug 02, 2012 at 11:27 AM ·
javascriptintbinary
Int to binary in unityscript
In javascript you can pass to binary i.e.
x = 2; x.toString(2) //01
Tried this but it won't except it. How do I pass in an int and get the binary equivalent?
Comment
Best Answer
Answer by Eric5h5 · Aug 02, 2012 at 06:33 PM
var x = 2;
var binaryString = System.Convert.ToString (x, 2);
Answer by gregzo · Aug 02, 2012 at 11:32 AM
var yourInt : int; //this is an int32, ie 4 bytes
var byteArray : Byte[] = new Byte[4];
byteArray = System.BitConverter.GetBytes(yourInt);
Oups, replied a bit fast. This will get you bytes, not bits...
nice one, it doesnt run in version 4, unity doesnt recognise Type : Byte.