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

2 vues (au cours des 30 derniers jours)
hex_str='0123';
actual answer is 0000000100100011 but matlab is not showing the starting zeros as it giving the answer 10010011
  2 commentaires
Walter Roberson
Walter Roberson le 4 Avr 2014
How are you doing the conversion?
kamila
kamila le 4 Avr 2014
by using the command hex2dec then dec2bin

Connectez-vous pour commenter.

Réponse acceptée

Azzi Abdelmalek
Azzi Abdelmalek le 4 Avr 2014
Modifié(e) : Azzi Abdelmalek le 4 Avr 2014
s='0123'
b=strjoin(cellfun(@(x) dec2bin(hex2dec(x),4),regexp(s,'.','match'),'un',0),'')

Plus de réponses (1)

Joseph Cheng
Joseph Cheng le 4 Avr 2014
Modifié(e) : Joseph Cheng le 4 Avr 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 commentaires
Joseph Cheng
Joseph Cheng le 4 Avr 2014
Again you're welcome, i wasn't sure if there were more to the statement Q('-')9
kamila
kamila le 4 Avr 2014
how can I apply this to hex_str='0123456789ABCDEF'

Connectez-vous pour commenter.

Catégories

En savoir plus sur Data Type Conversion dans Help Center et File Exchange

Tags

Community Treasure Hunt

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

Start Hunting!

Translated by