convert from hexa to binary??

66 visualizzazioni (ultimi 30 giorni)
Radwa
Radwa il 2 Feb 2015
Risposto: Limabean il 8 Dic 2022
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

Risposte (1)

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

Categorie

Scopri di più su Data Type Conversion in Help Center e File Exchange

Community Treasure Hunt

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

Start Hunting!

Translated by