Apr 07 2009

整型INT

Category: 技术ssmax @ 18:21:18

java里面是32位:

static int MAX_VALUE
          A constant holding the maximum value an int can have, 231-1.
static int MIN_VALUE
          A constant holding the minimum value an int can have, -231.

 

mysql里面也是默认的32位:

M indicates the maximum display width for integer types

 

TINYINT[(M)] [UNSIGNED] [ZEROFILL]

A very small integer. The signed range is -128 to 127. The unsigned range is 0 to 255.

  • SMALLINT[(M)] [UNSIGNED] [ZEROFILL]A small integer. The signed range is -32768 to 32767. The unsigned range is 0 to 65535.
  • MEDIUMINT[(M)] [UNSIGNED] [ZEROFILL]A medium-sized integer. The signed range is -8388608 to 8388607. The unsigned range is 0 to 16777215.
  • INT[(M)] [UNSIGNED] [ZEROFILL]A normal-size integer. The signed range is -2147483648 to 2147483647. The unsigned range is 0 to 4294967295.
  • INTEGER[(M)] [UNSIGNED] [ZEROFILL]This type is a synonym for INT.
  • BIGINT[(M)] [UNSIGNED] [ZEROFILL]A large integer. The signed range is -9223372036854775808 to 9223372036854775807. The unsigned range is 0 to 18446744073709551615.SERIAL is an alias for BIGINT UNSIGNED NOT NULL AUTO_INCREMENT UNIQUE.
  •  

    C的话就是看编译器了,32位就和java一样,现在基本都是32位的了,当初学TC的时候是16位的,造成一个错觉,一直都以为java的int类型虽然不是16位,但是也不够表示mysql里面的int,而且mysql里面int 是表示成 int(11) 的,而

    M indicates the maximum display width for integer types

    意思就是11表示的是mysql显示的列宽,而不是制定数据位数。。。以前竟然一直都以为11是指11位的十进制数,而32位的int最长是10位二进制,真是郁闷啊。。。哎,造成java编程的时候都用long来表示,不是一般的郁闷。。