Created
December 13, 2017 23:34
-
-
Save awnumar/a72e6d9badbc333b9db13a7af5041d37 to your computer and use it in GitHub Desktop.
Code snippet to encode a uint32 as binary, in C.
This file contains hidden or 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
// 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