LabWindows/CVI

cancel
Showing results for 
Search instead for 
Did you mean: 

Display a number in hex in C++

Let say I have:

 

char car=0xE2;

char str[10];

 

How do I put this value in string?

 

If I try:

sprintf(str,"%#x",car);

the result will be: 0xffffffe2

 

But I want to display only 0xe2.

How should I do it?

Thanks a lot

0 Kudos
Message 1 of 5
(4,010 Views)

Hi,

 

Try :

 

sprintf(str,"%#x",(unsigned char)car);

 

B.W.

0 Kudos
Message 2 of 5
(4,007 Views)
being pointy-haired as i am, i would say that using sprintf() is not C++ !
0 Kudos
Message 3 of 5
(3,955 Views)
As LabWindows/CVI is an environment based on ANSI C, the aforementioned approach might actually be best and a consideration for C++ could be considered out of context.
0 Kudos
Message 4 of 5
(3,914 Views)

a consideration for C++ is indeed out of context... i was just pointing out the obvious error in the title of the thread.

0 Kudos
Message 5 of 5
(3,907 Views)