You're viewing a comment by Some name and its responses.

Some name Permalink
September 05, 2018, 06:58

Hello i think your int to bin function is mislabeled it prints a char not a int. This is my suggestion for how to convert an int to bin while retaining old functionality.

void char_to_bin(char num) {
char str[9] = {0};
int i;
for (i=7; i>=0; i--) {
str[i] = (num&1)?'1':'0';
num >>= 1;
}
printf("%s ", str);
}

void int_to_bin(int num){
int i;
for(i=sizeof(int)-1;i>=0;--i){
char_to_bin(((char*)&num)[i]);
}
printf("\n");
}

Reply To This Comment

(why do I need your e-mail?)

(Your twitter handle, if you have one.)

Type the word "0day_143": (just to make sure you're a human)

Please preview the comment before submitting to make sure it's OK.