Skip to content

Instantly share code, notes, and snippets.

@awnumar
Created December 13, 2017 23:34
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 awnumar/a72e6d9badbc333b9db13a7af5041d37 to your computer and use it in GitHub Desktop.
Save awnumar/a72e6d9badbc333b9db13a7af5041d37 to your computer and use it in GitHub Desktop.
Code snippet to encode a uint32 as binary, in C.
// Encode the length into raw binary.
uint32_t rel_len = length;
unsigned char len_bytes[4];
len_bytes[0] = (rel_len >> 24) & 0xFF;
len_bytes[1] = (rel_len >> 16) & 0xFF;
len_bytes[2] = (rel_len >> 8) & 0xFF;
len_bytes[3] = rel_len & 0xFF;
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment