How do I convert a hexadecimal input from the user into binary form?

5 Ansichten (letzte 30 Tage)
Sahana Sridhar
Sahana Sridhar am 30 Mär. 2014
Kommentiert: sidra rahim am 2 Feb. 2019
this is the piece of code I am having trouble with:
h = input('Enter a hexadecimal string: ');
d = hex2dec(h);
b = dec2bin(d);
but this code doesn't produce the exact binary representation of the input for large hexadecimal strings. is there a way of converting hex to binary directly? also I'm using the Matlab R2010a student version, so please give me solutions compatible with this version only. Thank you

Antworten (1)

Azzi Abdelmalek
Azzi Abdelmalek am 30 Mär. 2014
Example
h='555F'
d = hex2dec(h)
b = dec2bin(d)
Now, what do you mean: I have trouble with this
  2 Kommentare
Sahana Sridhar
Sahana Sridhar am 30 Mär. 2014
for example,for large hexadecimal strings like the one below h = 'ABD7C41890EB527F648CA03DB51C793F' the conversion from hex2dec and then from dec2bin is being either rounded or truncated and therefore I'm unable to get a complete representation of the input hex string in binary. In the above example, there are 32 hex digits, but the resulting binary number converts only till the first half of the hex string, the later half of the string is simply displayed as zeros. I require selected 8-hex digits for further processing in my code. If the later part is displayed as only zeros, then my code will run erroneously.
sidra rahim
sidra rahim am 2 Feb. 2019
Did you find any solution for this problem?

Melden Sie sich an, um zu kommentieren.

Kategorien

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

Tags

Community Treasure Hunt

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

Start Hunting!

Translated by