Follow Slashdot blog updates by subscribing to our blog RSS feed

 



Forgot your password?
typodupeerror
×
User Journal

Journal Vagary's Journal: Hakmem Item 154

I'm curious whether Hakmem Item 154 works when not written in assembler. If you have access to a machine that you believe does not do twos-complement arithmetic, please run the following C99 program and report the results:

#include <stdio.h>
#include <stdlib.h>
#include <stdbool.h>
#include <assert.h>
static char*char2bin(register char x){char*r=(char*)malloc(sizeof(char)*8);assert(r!=NULL);for(register int i=1;i<9;++i,x>>=1)if((bool)(x&1))r[8-i]='1'; else r[8-i]='0';return r;}int main(){char*x=char2bin((char)0xFF+(char)0xFF); assert(x!=NULL);printf("%s\n",x);free(x);return EXIT_SUCCESS;}

(There are no system calls in there, so I think you should trust me even if you don't know exactly what it's doing.)

This discussion has been archived. No new comments can be posted.

Hakmem Item 154

Comments Filter:

UNIX was not designed to stop you from doing stupid things, because that would also stop you from doing clever things. -- Doug Gwyn

Working...