How to determine how many bytes an integer needs?

前端 未结 22 1613
悲&欢浪女
悲&欢浪女 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 02:53

    there are lots of great recipes for stuff like this over at Sean Anderson's "Bit Twiddling Hacks" page.

提交回复
热议问题