2

Let's say i have a 1x32 double array Input in matlab workspace. This variable has all positive decimal values. I want to convert each value to Hex & store it in another array Output
I use dec2hex(Input) & it generates a character string with Hex values. Now, i want an array of Hex numbers & not a string.
How do i convert this Hex string into Hex array of 1x32 Output
If i use str2num or str2double, it gives empty & NaN respectively?
How to do it

3
  • Hex numbers include strings (A,...,F) naturally, so the type would be string not `num'. Usually you can use 'dec2hex' and 'hex2num' functions together to convert to hex-string and convert back. And just use the hex-string for print and display stuff.
    – NKN
    Commented Jul 27, 2013 at 11:02
  • As i said, i want Hex array not Hex string because i want to send this array into Xilinx ISE Commented Jul 27, 2013 at 11:19
  • There is no "array of Hex numbers". The values of array elements are simply numbers. These numbers can be represented in decimal, hexadecimal, binary, or any number of other bases, but the underlying number is still the same. Also, hexadecimal representation of decimal values is very weird; normally the values would be integers.
    – beaker
    Commented Jul 28, 2013 at 16:12

2 Answers 2

5

to get neither empty nor Nan values use `hex2dec'. something like this works for me:

a=1:20; 
b=dec2hex(a); 
c=hex2dec(b)

ans =

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
1

Matlab does not manage hexadecimal numbers per se, only decimal notation. That's why matlab stores hexadecimal numbers in string format.

To do an addition of hex for example, you have to pass through the decimal notation:

a='ABC'; 
b='123'; 
c=dec2hex(hex2dec(a)+hex2dec(b))

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.