Last active
August 29, 2015 14:03
-
-
Save KeyMaster-/1a2a0d6ea6d70180ea91 to your computer and use it in GitHub Desktop.
haxe.io.Bytes to bit string representation
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import haxe.io.Bytes; | |
class BytesUtil { | |
/** | |
* Represent a Bytes object as single bits in a string | |
* @param b The bytes | |
* @return A string of '0's and '1's representing the bytes | |
*/ | |
public static function toBits(b:Bytes):String { | |
var s:String = ""; | |
for (i in 0...b.length) { | |
for (j in 0...8) { | |
s += Std.string(b.get(i) & (1 << (7 - j)) != 0 ? 1 : 0); | |
} | |
} | |
return s; | |
} | |
} |
Well there is also the toHex function which is why I called it toBits. Also, toString already exists which interprets bytes into characters to form a string.
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
More of a
toString()
really. :)