MATLAB Answers

Suhas Holla

I am having problem using hex2dec. It shows an error when it is used.

Asked by Suhas Holla
on 24 Mar 2013

I am using MATLAB R2009. And I have problem using hex2dec. I am permutating a the row element after using dec2hex, and then using hex2dec. and it show the following error message.

Error using ==> hex2dec at 38
Input string found with characters other than 0-9, a-f, or A-F.
Error in ==> crypt_d at 62

when i check the td8 variable the element which has zeros has been replaced by empty space as in

td8 =
0C F 9

the space between C and F and F and 9 is supposed to be zeros. Can anyone please tell how to overcome these problem.

this is the part of the code where error is occurring

for i=1:si
    decr4=[decr4 ; td8-ad4];


1 Answer

Answer by the cyclist
on 24 Mar 2013
Edited by the cyclist
on 24 Mar 2013

I am not sure where you got the variable de_hex4, but if you are confident that all you need to do is replace the spaces with zeros, then you can do that with the regexprep function:

td8 = regexprep(td8,' ','0');

before you then send it to hex2dec.


I think de_hex4 is a variable, but I do not know what was assigned to it.

the cyclist
on 24 Mar 2013

You are right. I wrote function instead of variable. I have edited.

Join the 15-year community celebration.

Play games and win prizes!

Learn more
Discover MakerZone

MATLAB and Simulink resources for Arduino, LEGO, and Raspberry Pi

Learn more

Discover what MATLAB® can do for your career.

Opportunities for recent engineering grads.

Apply Today

MATLAB Academy

New to MATLAB?

Learn MATLAB today!