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

2 次查看(过去 30 天)
hex_str='0123';
actual answer is 0000000100100011 but matlab is not showing the starting zeros as it giving the answer 10010011

采纳的回答

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 个评论

请先登录,再进行评论。

类别

Help CenterFile Exchange 中查找有关 Data Type Conversion 的更多信息

标签

Community Treasure Hunt

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

Start Hunting!

Translated by