how to convert negative integers(that are not between -127 and 0) to binary in matlab?

3 ビュー (過去 30 日間)
Jack Moriss
Jack Moriss 2016 年 11 月 18 日
編集済み: James Tursa 2016 年 11 月 18 日
hi. i want to convert these numbers to binary:b=[171 -7 4 -140].and i use this code: bitstream=dec2bin(typecast(int8(b),'uint8')); but it does not work correctly for numrbes that are not in this interval[-127 127] how can i convert them to binary and agian to integer correctly?

回答 (1 件)

James Tursa
James Tursa 2016 年 11 月 18 日
編集済み: James Tursa 2016 年 11 月 18 日
What range are they in? E.g., for a 16-bit range:
bitstream = dec2bin(typecast(int16(b),'uint16'));
You've got numbers outside the signed 8-bit range in your example, so it will simply not be possible to represent them using your 8-bit scheme. So maybe just using a 16-bit or 32-bit conversion will work for your application.

カテゴリ

Help Center および File ExchangeLogical についてさらに検索

タグ

Community Treasure Hunt

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

Start Hunting!

Translated by