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中整数所需的字节大小

        时间:2023-07-04
          <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中整数所需的字节大小的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持跟版网!

                  上一篇:Python中13位数字的范围和xrange? 下一篇:如何在不知道哪个更大的情况下找到两个值之间的差异?

                  相关文章

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

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

                    1. <tfoot id='1oM2w'></tfoot>
                      • <bdo id='1oM2w'></bdo><ul id='1oM2w'></ul>
                    2. <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>