📌Common📌二进制和位运算.txt
i << n 等于 i * 2^n
i >> n 等于 i / 2^n
i & (2^n-1) 等于 i % 2^n (eg: i&1 <=> i%2, i&3 <=> i%4, i&7 <=> i%8, i&15 <=> i%16)
特性:
i&0 = 0
i&i = i
i|0 = i
i|i = i
i^0 = i
i^i = 0
b字节(n=8b位)有符号整数的值范围是 [ - 2^(n-1), 2^(n-1) -1 ]
b字节(n=8b位)无符号整数的值范围是 [ 0, 2^n - 1 ]
+----------+--------+--------+---------------------+---------------------+
| MySQL | Go | C# | min | max |
+----------+--------+--------+---------------------+---------------------+
| tinyint | int8 | sbyte | -128 | 127 |
| ↳u | uint8 | byte | 0 | 255 |
| smallint | int16 | short | -32768 | 32767 |
| ↳u | uint16 | ushort | 0 | 65535 |
| int | int32 | int | -2147483648 | 2147483647 |
| ↳u | uint32 | uint | 0 | 4294967295 |
| bigint | int64 | long |-9223372036854775808 | 9223372036854775807 |
| ↳u | uint64 | ulong | 0 |18446744073709551615 |
+----------+--------+--------+---------------------+---------------------+
MySQL还有3字节整数mediumint,(类同int24和uint24)
min: -2^23 = -8388608
max: 2^23-1 = 8388607
usigned max: 2^24-1 = 16777215
Go的int和uint,C#的nint和nuint,是取决于运行环境的32位或64位有符号整型和无符号整型。
javascript中最大最小安全整数常量
Number.MIN_SAFE_INTEGER = -9007199254740991
Number.MAX_SAFE_INTEGER = 2^53-1 = 9007199254740991