a poorly optimized solution for integer null value

Integers use Two’s compliment which replaces the largest bit with a 1 for negative and a 0 for positive, which does negatively square the biggest number you can represent. 10000000 = -0, 00000000 = 0.

I have a question now, if integers are 4 bytes how come I can only assign 2 bytes worth of information to one?

#include <stdbool.h>
bool isnull(int num){
    char hex[4] = {0,0,0,0};
    sprintf(hex,"%X",num);
    if (hex[0] == '8' && hex[1] == '0' && hex[2] == '0' && hex[3] == '0'){
        return true;
    }
    return false;
}
int num = 0x8000;
// assign num using hex instead of base 10; -0, which gets translated to regular 0

8 in hex means 1000b
If you want to use binary for integers, use ‘0b1000000000000000’

Leave a Reply

Your email address will not be published. Required fields are marked *