Better HN
topnewbestaskshowjobs
Log inSign up

1010111

4 karma · joined Jan 11, 2017 (9y ago) · 3 submissions

Submissions

comment 9y ago · link · parent

Thanks, i was not aware of that. What is a possible fix?

comment 9y ago · link · parent

It uses a bit mask from the leftmost bit to the rightmost and prints the respective bits in x. Is that more complicated than allocating memory on the heap, storing the bits, and then printing them in reverse?

Also the code above does not contain anything C specific, with the exception of 'putchar' let's say.

comment 9y ago · link · parent

Shitty C code: the binary printing function is needlessly complicated.

    void print_bin(int x){  
	for(unsigned m=~(~0u>>1); m ; m>>=1)  
		putchar(x&m?'1':'0');  
	putchar('\n');  
    }