Hex 01A9 to 16-binary?
古いコメントを表示
I am trying to convert this input 01A9 into binary
4bit Hex input
01A9
16bit Binary Output
0000 0001 1010 1001
**no spaces
採用された回答
その他の回答 (2 件)
No loops, no padding, works correctly for any number of hex digits (not just 16 bits):
H = '01A9';
B = reshape(dec2bin(sscanf(H,'%1x'),4).',1,[])
James Tursa
2020 年 12 月 16 日
編集済み: James Tursa
2020 年 12 月 16 日
E.g., if H is not too big:
H = '01A9';
B = dec2bin(hex2dec(H),numel(H)*4)
Otherwise you will need some form of a loop (explicit or hidden in a function call). E.g.,
C = arrayfun(@(h)dec2bin(hex2dec(h),4),H,'uni',false);
B = [C{:}]
カテゴリ
ヘルプ センター および File Exchange で Logical についてさらに検索
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!