Size of int and float

后端 未结 6 741
夕颜
夕颜 2021-02-01 07:17

I have a question about the ranges of ints and floats:

If they both have the same size of 4 bytes, why do they have different ranges?

6条回答
  •  抹茶落季
    2021-02-01 07:19

    You are mixing the representation of a number, which is dependent upon some rules you (or somebody else) defines, and the way you use to keep the number in the computer (the bytes).

    For example, you can use only one bit to keep a number, and decide that 0 represents -100, and 1 represents +100. Or that 0 represents .5 and 1 represents 1.0. The 2 things, the data and the meaning of the data, are independent.

提交回复
热议问题