您需要多少位存储一个正整数? [英] How many bits do you need to store a positive integer?

查看:68
本文介绍了您需要多少位存储一个正整数?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

您需要多少位存储一个正整数(例如,十亿)?您是否必须使用log2 N才能找到答案?

How many bits would you need to store a positive integer for example in the billions? Would you have to use the log2 N to find this out?

推荐答案

由于我已经看到很多次错误地报告了答案,所以我想我应该发布正确的答案.

Since I've seen the answer reported incorrectly so many times, I thought I would post the correct answer.

表示正整数n所需的位数是

The number of bits needed to represent the positive integer n is

bits = floor( log2(n) + 1 )

其中log2表示以2为底的日志.

where log2 means log base 2.

这篇关于您需要多少位存储一个正整数?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆