dec2bin is adding inappropriate 0s to negative numbers when numBits is specified

5 ビュー (過去 30 日間)
Andrew
Andrew 2020 年 5 月 17 日
編集済み: Fangjun Jiang 2020 年 5 月 18 日
e.g. dec2bin(-23, 10) produces '0011101001', but it should produce '1111101001'.
  2 件のコメント
Andrew
Andrew 2020 年 5 月 17 日
My version doesn't specify that non-negative numbers are a problem. For example, it correctly converts -23 when numBits isn't specified.
Stephen23
Stephen23 2020 年 5 月 18 日
@David Goodmanson:
"Starting in R2020a, the dec2bin function converts negative numbers using their two's complement binary values."

サインインしてコメントする。

採用された回答

Fangjun Jiang
Fangjun Jiang 2020 年 5 月 17 日
編集済み: Fangjun Jiang 2020 年 5 月 18 日
Report to tech support. I think it looks like a bug.
From "doc dec2bin" in R2020a
Starting in R2020a, the dec2bin function converts negative numbers using their two's complement binary values.
version
ans =
'9.8.0.1376261 (R2020a) Update 2'
dec2bin(-23)
ans =
'11101001'
dec2bin(-23,8)
ans =
'11101001'
dec2bin(-23,9)
ans =
'011101001'

その他の回答 (1 件)

Walter Roberson
Walter Roberson 2020 年 5 月 17 日
Yes, it is a bug; if you want to report it yourself (the more people who report, the higher the priority), you can refer to case 04106030

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by