When should I use UNSIGNED and SIGNED INT in MySQL?

后端 未结 8 697
后悔当初
后悔当初 2020-12-07 12:45

When should I use UNSIGNED and SIGNED INT in MySQL ? What is better to use or this is just personal prefernce ? Because I\'ve seen it used like this;

id INT         


        
8条回答
  •  时光说笑
    2020-12-07 13:12

    I don't not agree with vipin cp.

    The true is that first bit is used for represent the sign. But 1 is for negative and 0 is for positive values. More over negative values are coded in different way (two's complement). Example with TINYINT:

    The sign bit
    |
    1000 0000b = -128d  
    ...  
    1111 1101b = -3d  
    1111 1110b = -2d  
    1111 1111b = -1d  
    
    0000 0000b = 0d  
    0000 0001b = 1d  
    0000 0010b = 2d  
    ...  
    0111 1111b = 127d  
    

提交回复
热议问题