How does c++ represent negative value

As i know binary equivalent of signed int is 11111111111111111111111111111111
and based on this, I’m trying to make Maximum and Minimum int value for my program without using limits.h header file. After run my below code i get Minimum value as -2147483648 and Maximum value is 0. Here below is my code:

int MaxInt(){
      int MAX = -1;
      MAX = 0 << ((sizeof(int)*8)-1);

     return MAX;
}


int MinInt(){
      int MIN = 0;
      MIN  = 1 << ((sizeof(int)*8)-1);

     return MIN;
}

Whats wrong with my implementation.

Leave a Comment