Skip to content

Instantly share code, notes, and snippets.

@juliendkim
juliendkim / mem_to_bit.c
Created October 23, 2019 02:55
How variables are represented in memory
#include <stdio.h>
#include <stdlib.h>
#define MEM_TO_BIN(obj) mem_to_bin((char[sizeof(obj) * 9 + 1]){""}, &(obj), sizeof(obj))
char *mem_to_bin(char *buffer, void *object, size_t sizeof_object) {
const unsigned char *p = (const unsigned char *)object;
p += sizeof_object;
char *s = buffer;
while (sizeof_object-- > 0) {