久久久久久久av_日韩在线中文_看一级毛片视频_日本精品二区_成人深夜福利视频_武道仙尊动漫在线观看

Python中的二進(jìn)制補碼?

Two#39;s Complement Binary in Python?(Python中的二進(jìn)制補碼?)
本文介紹了Python中的二進(jìn)制補碼?的處理方法,對大家解決問題具有一定的參考價值,需要的朋友們下面隨著小編來一起學(xué)習(xí)吧!

問題描述

Python 中的整數(shù)存儲在二進(jìn)制補碼中,對嗎?

Integers in Python are stored in two's complement, correct?

雖然:

>>> x = 5
>>> bin(x)
0b101

還有:

>>> x = -5
>>> bin(x)
-0b101

這很蹩腳.如何讓 python 給我 REAL 二進(jìn)制位的數(shù)字,并且前面沒有 0b?所以:

That's pretty lame. How do I get python to give me the numbers in REAL binary bits, and without the 0b infront of it? So:

>>> x = 5
>>> bin(x)
0101
>>> y = -5
>>> bin(y)
1011

推薦答案

不確定如何使用標(biāo)準(zhǔn)庫獲得所需的內(nèi)容.有一些腳本和包可以為您進(jìn)行轉(zhuǎn)換.

Not sure how to get what you want using the standard lib. There are a handful of scripts and packages out there that will do the conversion for you.

我只是想說明為什么",以及為什么它不蹩腳.

I just wanted to note the "why" , and why it's not lame.

bin() 不返回二進(jìn)制位.它將數(shù)字轉(zhuǎn)換為二進(jìn)制字符串.根據(jù) python 語言定義,前導(dǎo) '0b' 告訴解釋器您正在處理二進(jìn)制數(shù).這樣你就可以直接使用二進(jìn)制數(shù),就像這樣

bin() doesn't return binary bits. it converts the number to a binary string. the leading '0b' tells the interpreter that you're dealing with a binary number , as per the python language definition. this way you can directly work with binary numbers, like this

>>> 0b01
1
>>> 0b10
2
>>> 0b11
3
>>> 0b01 + 0b10
3

這不是蹩腳的.太好了.

that's not lame. that's great.

http://docs.python.org/library/functions.html#bin

bin(x)

將整數(shù)轉(zhuǎn)換為二進(jìn)制字符串.

Convert an integer number to a binary string.

http://docs.python.org/reference/lexical_analysis.html#integers

整數(shù)和長整數(shù)文字由以下詞法定義描述:

Integer and long integer literals are described by the following lexical definitions:

bininteger ::= "0" ("b" | "B") bindigit+

bininteger ::= "0" ("b" | "B") bindigit+

bindigit ::= "0" |1"

bindigit ::= "0" | "1"

這篇關(guān)于Python中的二進(jìn)制補碼?的文章就介紹到這了,希望我們推薦的答案對大家有所幫助,也希望大家多多支持html5模板網(wǎng)!

【網(wǎng)站聲明】本站部分內(nèi)容來源于互聯(lián)網(wǎng),旨在幫助大家更快的解決問題,如果有圖片或者內(nèi)容侵犯了您的權(quán)益,請聯(lián)系我們刪除處理,感謝您的支持!

相關(guān)文檔推薦

How to draw a rectangle around a region of interest in python(如何在python中的感興趣區(qū)域周圍繪制一個矩形)
How can I detect and track people using OpenCV?(如何使用 OpenCV 檢測和跟蹤人員?)
How to apply threshold within multiple rectangular bounding boxes in an image?(如何在圖像的多個矩形邊界框中應(yīng)用閾值?)
How can I download a specific part of Coco Dataset?(如何下載 Coco Dataset 的特定部分?)
Detect image orientation angle based on text direction(根據(jù)文本方向檢測圖像方向角度)
Detect centre and angle of rectangles in an image using Opencv(使用 Opencv 檢測圖像中矩形的中心和角度)
主站蜘蛛池模板: 欧美在线激情 | 久久激情av| 中文字幕一区二区三区精彩视频 | 精品国模一区二区三区欧美 | 欧美一区二区在线观看 | 中文字幕欧美日韩一区 | 亚洲一区二区三区四区在线观看 | 久久精品视频99 | 欧美极品少妇xxxxⅹ免费视频 | 视频二区在线观看 | 男人av的天堂 | 免费a大片 | 国产亚洲精品久久久久动 | 天堂在线免费视频 | 777zyz色资源站在线观看 | 国产免费让你躁在线视频 | 777777777亚洲妇女 | 黄色大片网站 | 韩国电影久久 | 国产精品久久国产精品 | 国产精品日韩高清伦字幕搜索 | 亚洲三级免费看 | 色婷婷亚洲一区二区三区 | 日韩精品在线观看一区二区 | 亚洲精品久久久久中文字幕欢迎你 | av黄色在线观看 | 狠狠久久 | 久久久久久国产精品免费免费狐狸 | 日韩精品在线观看一区二区 | 欧美男人天堂 | 在线观看中文视频 | 很黄很污的网站 | 青青99 | 国产午夜精品理论片a大结局 | 一区二区三区av | 天天操夜夜操 | 欧美精品日韩 | 亚洲www啪成人一区二区 | 99精品网| 狠狠操狠狠干 | 中文字幕高清 |