convert from hexa to binary??

51 次查看(过去 30 天)
Radwa
Radwa 2015-2-2
回答: Limabean 2022-12-8
I have 32 bits in hexa I want to convert it to binary without lossing accuracy? I used hex2dec and then dec2bin but the output is n't as expected. ex:
v=('981ba682 4c1bfb1a b4854720 29b71d80')
v(v == ' ') = []
v=hex2dec(v)
v=dec2bin(v)
this is the expected o/p : 10011000 00011011 10100110 10000010 01001100 00011011 11111011 00011010
10110100 10000101 01000111 00100000 00101001 10110111 00011101 10000000
but I got:
10011000000110111010011010000010010011000001101111111000000000000000000000000000000000000000000000000000000000000000000000000000

回答(1 个)

Limabean
Limabean 2022-12-8
Slightly different approach:
newStr = regexprep('981ba682 4c1bfb1a b4854720 29b71d80','([A-F0-9])','${dec2bin(hex2dec($1))}','ignorecase')
newStr = '10011000110111010110100010 1001100110111111101111010 10111001000101100111100 10100110111111110110000'

类别

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