basic binary encoding and decoding utility functions