How to determine how many bytes an integer needs?

前端 未结 22 1542
悲&欢浪女
悲&欢浪女 2020-12-13 02:13

I\'m looking for the most efficient way to calculate the minimum number of bytes needed to store an integer without losing precision.

e.g.

int: 10 = 1 byte
         


        
22条回答
  •  既然无缘
    2020-12-13 03:10

    Why not just use a 32-bit hash?


    That will work at near-top-speed everywhere.

    I'm rather confused as to why a large hash would even be wanted. If a 4-byte hash works, why not just use it always? Excepting cryptographic uses, who has hash tables with more then 232 buckets anyway?

提交回复
热议问题