Skip to content

Instantly share code, notes, and snippets.

@KeyMaster-
Last active Aug 29, 2015
Embed
What would you like to do?
haxe.io.Bytes to bit string representation
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;
}
}
@Gama11
Copy link

Gama11 commented Jul 7, 2014

More of a toString() really. :)

@KeyMaster-
Copy link
Author

KeyMaster- commented Jul 7, 2014

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