How to convert hex number '0' to binary when it is at first place in a bit stream

2 ビュー (過去 30 日間)
kamila
kamila 2014 年 4 月 4 日
コメント済み: kamila 2014 年 4 月 4 日
hex_str='0123';
actual answer is 0000000100100011 but matlab is not showing the starting zeros as it giving the answer 10010011
  2 件のコメント
Walter Roberson
Walter Roberson 2014 年 4 月 4 日
How are you doing the conversion?
kamila
kamila 2014 年 4 月 4 日
by using the command hex2dec then dec2bin

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

採用された回答

Azzi Abdelmalek
Azzi Abdelmalek 2014 年 4 月 4 日
編集済み: Azzi Abdelmalek 2014 年 4 月 4 日
s='0123'
b=strjoin(cellfun(@(x) dec2bin(hex2dec(x),4),regexp(s,'.','match'),'un',0),'')

その他の回答 (1 件)

Joseph Cheng
Joseph Cheng 2014 年 4 月 4 日
編集済み: Joseph Cheng 2014 年 4 月 4 日
reading the documentation on dec2bin you can specify the number of bits
>> hexstr= '0123';
>> n=length(hexstr);
>> d = hex2dec(hexstr);
>> dec2bin(d,2^n)
  4 件のコメント
Joseph Cheng
Joseph Cheng 2014 年 4 月 4 日
Again you're welcome, i wasn't sure if there were more to the statement Q('-')9
kamila
kamila 2014 年 4 月 4 日
how can I apply this to hex_str='0123456789ABCDEF'

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

カテゴリ

Help Center および File ExchangeData Type Conversion についてさらに検索

タグ

Community Treasure Hunt

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

Start Hunting!

Translated by