{"id":341156,"date":"2021-02-16T00:00:57","date_gmt":"2021-02-15T16:00:57","guid":{"rendered":"http:\/\/4563.org\/?p=341156"},"modified":"2021-02-16T00:00:57","modified_gmt":"2021-02-15T16:00:57","slug":"python-%e7%9a%84-int-bit_length-%e5%87%bd%e6%95%b0%e7%9a%84%e6%97%b6%e9%97%b4%e5%a4%8d%e6%9d%82%e5%ba%a6%e6%98%af%e5%a4%9a%e5%b0%91%e5%91%a2%ef%bc%9f","status":"publish","type":"post","link":"http:\/\/4563.org\/?p=341156","title":{"rendered":"Python \u7684 int.bit_length() \u51fd\u6570\u7684\u65f6\u95f4\u590d\u6742\u5ea6\u662f\u591a\u5c11\u5462\uff1f"},"content":{"rendered":"<div>\n<div>\n<div>\n<h1>                  Python \u7684 int.bit_length() \u51fd\u6570\u7684\u65f6\u95f4\u590d\u6742\u5ea6\u662f\u591a\u5c11\u5462\uff1f               <\/h1>\n<p> <\/p>\n<div>\n<div> <span>\u8cc7\u6df1\u5927\u4f6c : littleMaple <\/span>  <span><i><\/i> 2<\/span> <\/div>\n<div> <\/div>\n<\/p><\/div>\n<\/p><\/div>\n<\/p><\/div>\n<div isfirst=\"1\"> <\/p>\n<p>\u5047\u8bbe\u67d0\u6574\u6570 <code>x<\/code> \u7684\u4e8c\u8fdb\u5236\u6700\u9ad8\u6709\u6548\u4f4d\u4f4d\u6570\u4e3a <code>n<\/code>\uff0c\u90a3\u4e48 <code>x.bit_length()<\/code> \u7684\u65f6\u95f4\u590d\u6742\u5ea6\u662f <code>O(n)<\/code> \u8fd8\u662f <code>O(1)<\/code> \u5462\uff1f<\/p>\n<\/p><\/div>\n<div> <b>\u5927\u4f6c\u6709\u8a71\u8aaa<\/b> (<span>6<\/span>)        <\/div>\n<div> <\/div>\n<\/p><\/div>\n<\/p><\/div>\n<ul>\n<li data-pid=\"5269083\" data-uid=\"2\">\n<div>\n<div>\n<div> <span>\u8cc7\u6df1\u5927\u4f6c : mogg <\/span>  <\/div>\n<div> <i title=\"\u5f15\u7528\"><\/i>  <span>          <\/span> <\/div>\n<\/p><\/div>\n<div>                                                             log n \u554a\u2026\u2026                                                            <\/div>\n<\/p><\/div>\n<\/li>\n<li data-pid=\"5269084\" data-uid=\"2\">\n<div>\n<div>\n<div> <span>\u8cc7\u6df1\u5927\u4f6c : mogg <\/span>  <\/div>\n<div> <i title=\"\u5f15\u7528\"><\/i>  <span>          <\/span> <\/div>\n<\/p><\/div>\n<div>                                                             \u5bf9\u4e0d\u8d77\u770b\u9519\u4e86\uff0c\u5e38\u89c4\u7b97\u6cd5\u662f O(log x ) or O(n)<br \/>\u56fa\u5b9a\u4f4d\u6570\u6709\u4f18\u5316\u5230 O(log 32\/64\u2026\u2026)\u7684\u7b97\u6cd5\uff08\u8bb0\u5f97 csapp \u4e0a\u6709\uff09<br \/>Python \u7684\u5177\u4f53\u5b9e\u73b0\u5f97\u770b\u770b\u6e90\u7801\uff08                                                            <\/div>\n<\/p><\/div>\n<\/li>\n<li data-pid=\"5269085\" data-uid=\"2\">\n<div>\n<div>\n<div> <span>\u8cc7\u6df1\u5927\u4f6c : lxy42 <\/span>  <\/div>\n<div> <i title=\"\u5f15\u7528\"><\/i>  <span>          <\/span> <\/div>\n<\/p><\/div>\n<div>                                                             \u6b63\u597d\u5728\u770b Python \u6e90\u7801, [int_bit_length_impl]( https:\/\/github.com\/python\/cpython\/blob\/master\/Objects\/longobject.c#L5256).<\/p>\n<p>\u4ece\u6e90\u7801\u6765\u770b\u662f O(1).                                                            <\/p><\/div>\n<\/p><\/div>\n<\/li>\n<li data-pid=\"5269086\" data-uid=\"2\">\n<div>\n<div>\n<div> <span>\u4e3b<\/span> <span>\u8cc7\u6df1\u5927\u4f6c : littleMaple <\/span>  <\/div>\n<div> <i title=\"\u5f15\u7528\"><\/i>  <span>          <\/span> <\/div>\n<\/p><\/div>\n<div>                                                             @lxy42 #3 \u611f\u8c22\u89e3\u60d1\uff01                                                            <\/div>\n<\/p><\/div>\n<\/li>\n<li data-pid=\"5269087\" data-uid=\"2\">\n<div>\n<div>\n<div> <span>\u4e3b<\/span> <span>\u8cc7\u6df1\u5927\u4f6c : littleMaple <\/span>  <\/div>\n<div> <i title=\"\u5f15\u7528\"><\/i>  <span>          <\/span> <\/div>\n<\/p><\/div>\n<div>                                                             @mogg #2 \u611f\u8c22\u56de\u590d\uff01\u6211\u8fd9\u5c31\u53bb\u770b CSAPP\uff0c\u4e4b\u524d\u4e00\u76f4\u653e\u7740.                                                            <\/div>\n<\/p><\/div>\n<\/li>\n<li data-pid=\"5269088\" data-uid=\"2\">\n<div>\n<div>\n<div> <span>\u8cc7\u6df1\u5927\u4f6c : msg7086 <\/span>  <\/div>\n<div> <i title=\"\u5f15\u7528\"><\/i>  <span>          <\/span> <\/div>\n<\/p><\/div>\n<div>                                                             \u672c\u8d28\u4e0a\u5e94\u8be5\u662f lzcnt \u5427\uff0c\u8ba9 CPU \u7b97\u7684\u8bdd\u662f\u5e38\u6570\u65f6\u95f4\u3002<br \/>\u5f92\u624b\u7b97\u7684\u8bdd\u5e94\u8be5\u4e5f\u80fd\u4f18\u5316\u5230\u5e38\u6570\u65f6\u95f4\u3002                                                            <\/div>\n<\/p><\/div>\n<\/li>\n<li>\n","protected":false},"excerpt":{"rendered":"<p>Python \u7684 int.bit_&hellip;<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":[],"categories":[],"tags":[],"_links":{"self":[{"href":"http:\/\/4563.org\/index.php?rest_route=\/wp\/v2\/posts\/341156"}],"collection":[{"href":"http:\/\/4563.org\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"http:\/\/4563.org\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"http:\/\/4563.org\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"http:\/\/4563.org\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=341156"}],"version-history":[{"count":0,"href":"http:\/\/4563.org\/index.php?rest_route=\/wp\/v2\/posts\/341156\/revisions"}],"wp:attachment":[{"href":"http:\/\/4563.org\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=341156"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"http:\/\/4563.org\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=341156"},{"taxonomy":"post_tag","embeddable":true,"href":"http:\/\/4563.org\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=341156"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}