News for hackers. Stuff that matters.

1010111

Re:Two's complement – You beauty on Wednesday January 11, 2017 @02:19PM (#13376677)
Thanks, i was not aware of that. What is a possible fix?
Re:Two's complement – You beauty on Wednesday January 11, 2017 @03:50AM (#13372635)
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.

Re:Two's complement – You beauty on Wednesday January 11, 2017 @02:34AM (#13372402)
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');  
    }