Skip to content

Instantly share code, notes, and snippets.

@xentec
Last active August 21, 2018 20:35
Show Gist options
  • Save xentec/d78e4739ac937853f45884371aebf1ef to your computer and use it in GitHub Desktop.
Save xentec/d78e4739ac937853f45884371aebf1ef to your computer and use it in GitHub Desktop.
#include <cstdint>
#include <fmt/format.h>
int main()
{
union {
uint32_t i;
uint8_t a[4];
struct { uint32_t lsb:6, m:20, msb:6; } b;
};
i = 0xFF02FF40;
fmt::print("ARRAY: "); for(int j=4;j>0;--j) fmt::print("{:08b}", a[j-1]); fmt::print("\n");
fmt::print("INT: {:032b}\n", i);
fmt::print("FIELDS: {:06b}{:020b}{:06b}\n", b.msb, b.m, b.lsb);
return 0;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment