all repos — nand2tetris @ 1a738e55ade7983f9c5b158ff325c19d5f5c7672

my nand2tetris progress

projects/06/bindump.h

 1
 2
 3
 4
 5
 6
 7
 8
 9
 10
 11
 12
 13
 14
 15
 16
 17
 18
 19
 20
 21
#include <stdio.h>
#include <stdint.h>

void bindump_word16(uint16_t w)
{
	unsigned char i, msb;
	char binary_string[17];
	binary_string[16] = '\0';

	for (i = 0; i < 16; ++i) {
		msb = (char)(w >> 15);

		if (msb != 0)
			binary_string[i] = '1';
		else
			binary_string[i] = '0';
		w <<= 1;
	}
	printf("%s", binary_string);
}