Filter löschen
Filter löschen

convert from hexa to binary??

52 Ansichten (letzte 30 Tage)
Radwa
Radwa am 2 Feb. 2015
Beantwortet: Limabean am 8 Dez. 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

Antworten (1)

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

Kategorien

Mehr zu Data Type Conversion finden Sie in Help Center und File Exchange

Community Treasure Hunt

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

Start Hunting!

Translated by