1. <i id='8Shd0'><tr id='8Shd0'><dt id='8Shd0'><q id='8Shd0'><span id='8Shd0'><b id='8Shd0'><form id='8Shd0'><ins id='8Shd0'></ins><ul id='8Shd0'></ul><sub id='8Shd0'></sub></form><legend id='8Shd0'></legend><bdo id='8Shd0'><pre id='8Shd0'><center id='8Shd0'></center></pre></bdo></b><th id='8Shd0'></th></span></q></dt></tr></i><div id='8Shd0'><tfoot id='8Shd0'></tfoot><dl id='8Shd0'><fieldset id='8Shd0'></fieldset></dl></div>

      <small id='8Shd0'></small><noframes id='8Shd0'>

        • <bdo id='8Shd0'></bdo><ul id='8Shd0'></ul>
        <legend id='8Shd0'><style id='8Shd0'><dir id='8Shd0'><q id='8Shd0'></q></dir></style></legend>
      1. <tfoot id='8Shd0'></tfoot>

        获取Python中整数所需的字节大小

        Get size in Bytes needed for an integer in Python(获取Python中整数所需的字节大小)
          <bdo id='OVLnY'></bdo><ul id='OVLnY'></ul>

          <small id='OVLnY'></small><noframes id='OVLnY'>

          <legend id='OVLnY'><style id='OVLnY'><dir id='OVLnY'><q id='OVLnY'></q></dir></style></legend>
                  <tbody id='OVLnY'></tbody>

              1. <tfoot id='OVLnY'></tfoot>
                <i id='OVLnY'><tr id='OVLnY'><dt id='OVLnY'><q id='OVLnY'><span id='OVLnY'><b id='OVLnY'><form id='OVLnY'><ins id='OVLnY'></ins><ul id='OVLnY'></ul><sub id='OVLnY'></sub></form><legend id='OVLnY'></legend><bdo id='OVLnY'><pre id='OVLnY'><center id='OVLnY'></center></pre></bdo></b><th id='OVLnY'></th></span></q></dt></tr></i><div id='OVLnY'><tfoot id='OVLnY'></tfoot><dl id='OVLnY'><fieldset id='OVLnY'></fieldset></dl></div>

                1. 本文介绍了获取Python中整数所需的字节大小的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着跟版网的小编来一起学习吧!

                  问题描述

                  如何找出某个整数占用的存储字节数?

                  How can I find out the number of Bytes a certain integer number takes up to store?

                  例如对于

                  • 十六进制x00 - xff(或十进制0 - 255 = 二进制0000 0000 - 1111 1111) 我希望得到 1(字节),
                  • 十六进制x100 - xffff(或十进制256 - 65535 = 二进制0000 00010000 0000 - 1111 1111 1111 1111) 会给我 2(字节)
                  • hexadecimal x00 - xff (or decimal 0 - 255 = binary 0000 0000 - 1111 1111) I'm looking to get 1 (Byte),
                  • hexadecimal x100 - xffff (or decimal 256 - 65535 = binary 0000 0001 0000 0000 - 1111 1111 1111 1111) would give me 2 (Bytes)

                  等等.

                  输入十六进制或十进制格式的任何线索?

                  Any clue for hexadecimal or decimal format as the input?

                  推荐答案

                  你可以使用简单的数学:

                  You can use simple math:

                  >>> from math import log
                  >>> def bytes_needed(n):
                  ...     if n == 0:
                  ...         return 1
                  ...     return int(log(n, 256)) + 1
                  ...
                  >>> bytes_needed(0x01)
                  1
                  >>> bytes_needed(0x100)
                  2
                  >>> bytes_needed(0x10000)
                  3
                  

                  这篇关于获取Python中整数所需的字节大小的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持跟版网!

                  本站部分内容来源互联网,如果有图片或者内容侵犯了您的权益,请联系我们,我们会在确认后第一时间进行删除!

                  相关文档推荐

                  env: python: No such file or directory(env: python: 没有这样的文件或目录)
                  How to evaluate environment variables into a string in Python?(如何在 Python 中将环境变量评估为字符串?)
                  Python - temporarily modify the current process#39;s environment(Python - 临时修改当前进程的环境)
                  Change current process environment#39;s LD_LIBRARY_PATH(更改当前进程环境的 LD_LIBRARY_PATH)
                  Reading and writing environment variables in Python?(在 Python 中读写环境变量?)
                  When to use sys.path.append and when modifying %PYTHONPATH% is enough(何时使用 sys.path.append 以及何时修改 %PYTHONPATH% 就足够了)

                  1. <legend id='1oM2w'><style id='1oM2w'><dir id='1oM2w'><q id='1oM2w'></q></dir></style></legend>

                    <small id='1oM2w'></small><noframes id='1oM2w'>

                      <tbody id='1oM2w'></tbody>

                        • <tfoot id='1oM2w'></tfoot>
                          • <bdo id='1oM2w'></bdo><ul id='1oM2w'></ul>
                          • <i id='1oM2w'><tr id='1oM2w'><dt id='1oM2w'><q id='1oM2w'><span id='1oM2w'><b id='1oM2w'><form id='1oM2w'><ins id='1oM2w'></ins><ul id='1oM2w'></ul><sub id='1oM2w'></sub></form><legend id='1oM2w'></legend><bdo id='1oM2w'><pre id='1oM2w'><center id='1oM2w'></center></pre></bdo></b><th id='1oM2w'></th></span></q></dt></tr></i><div id='1oM2w'><tfoot id='1oM2w'></tfoot><dl id='1oM2w'><fieldset id='1oM2w'></fieldset></dl></div>