LabWindows/CVI

cancel
Showing results for 
Search instead for 
Did you mean: 

decimal to hex

Hello
So here's my situation.  Imagine a numeric, and the user sets the value on the numeric to whatever (lets say 20).  I need to convert the number to hex and then use these numbers in an array.  I have no problem converting it to hex and getting a 2 bit number (for 20, the number would be 14).  However, in order for the number to work in the array, it must be of the form 0x14.  Obviously, it won't let me do 0x(MSB)(LSB) b/c my variables need to be constant, and I tried using an array and that didn't work (although I'm not sure if I did it right).  Any suggestions on what I should do?
neemtt
0 Kudos
Message 1 of 4
(3,769 Views)

I don't understand your question. Do you want to store a number in a numeric array? So no need to conversion for this! (you are maybe confusing a number with its representation -decimal, octal, hexadecimal, binary)

If on the other hand you want to store a hex representation of the number in a string (character array) you may find useful the %X operator: sprintf (string, "0x%x", number); will return a string with value "0x14" with number = 20



Proud to use LW/CVI from 3.1 on.

My contributions to the Developer Community
________________________________________
If I have helped you, why not giving me a kudos?
0 Kudos
Message 2 of 4
(3,764 Views)
sprintf was what I was looking for.
Thanks, and sorry for the poorly worded question.
Cheers
neemtt
0 Kudos
Message 3 of 4
(3,759 Views)
It sounds like you are new to C, and possibly programming in general. I recommend spending some time with a good C reference book (either Kernighan & Ritchie or Harbison & Steele).

Mert A.
National Instruments
0 Kudos
Message 4 of 4
(3,738 Views)