What is the significance of the number, 32767? [du

2019-06-14 18:39发布

This question already has an answer here:

I realize in some programming languages, random number generators generate a default value of 0 to 32767 (for example, in php, rand(); will return a float between 0 and 32767). What is the significance of such a random number? (As it is not a power of two or anything special like that.)

标签: php random
3条回答
ら.Afraid
2楼-- · 2019-06-14 19:21

32767 + 1 is a power of 2 Binary representation of numbers uses powers of 2. So, in an 4-bit structure, 0101 is 2^0 x 1, 2^1 x 0, 2^2 x 1, and 2^3 x 0 which is 5.

The MSB is used for sign and unsigned integers.

查看更多
做自己的国王
3楼-- · 2019-06-14 19:26

It is 2^15-1, so the max. value of a 16 bit signed int.

查看更多
三岁会撩人
4楼-- · 2019-06-14 19:32

I guess, On 16-bit implementations (still common when the C89 standard was written) that was the largest signed integer.

查看更多
登录 后发表回答