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

2 views (last 30 days)
hex_str='0123';
actual answer is 0000000100100011 but matlab is not showing the starting zeros as it giving the answer 10010011

Accepted Answer

Azzi Abdelmalek
Azzi Abdelmalek on 4 Apr 2014
Edited: Azzi Abdelmalek on 4 Apr 2014
s='0123'
b=strjoin(cellfun(@(x) dec2bin(hex2dec(x),4),regexp(s,'.','match'),'un',0),'')

More Answers (1)

Joseph Cheng
Joseph Cheng on 4 Apr 2014
Edited: Joseph Cheng on 4 Apr 2014
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 Comments

Sign in to comment.

Categories

Find more on Data Type Conversion in Help Center and File Exchange

Tags

Community Treasure Hunt

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

Start Hunting!