LabWindows/CVI

cancel
Showing results for 
Search instead for 
Did you mean: 

How to Display HEX values in specified format using Fmt function?

unsigned char data[6];
char readBuffer[20];
 
data[0] = 0x00;
data[1] = 0X0E;
data[2] = 0x12;
data[3] = 0x08;
data[4] = 0x00;
data[5] = 0x00;
 
Fmt(readBuffer,"%x %x %x %x %x %x",  data[0], data[1], data[2], data[3], data[4], data[5]);
 
The result is: 0 e 12 8 0 0
 
If I want to display the data value as "00 0E 12 08 00 00", how could I use the Fmt function?
 
 
0 Kudos
Message 1 of 6
(6,131 Views)

I usually use the standard ANSI printf() family for formatted output - here you could use the formatting string "%02X %02X %02X %02X %02X %02X" to produce the output you need. I don't know if Fmt() will recognise this formatting in the same way but its worth a try.

JR

Message 2 of 6
(6,123 Views)
Hi JR,
 
It seems that Fmt() does not recognise this formatting in the same way as sprintf()...
But I can use sprintf() instead so as to implement the function.
Thanks very much for your answer!
 
Carol_Cai
0 Kudos
Message 3 of 6
(6,120 Views)
Hi carol,
 
Fortunatly I dont have an available compiler right now , but I think that :
 
Fmt(readBuffer,"%x[w0p2] %x[w2p0] %x[w2p0] %x[w2p0] %x[w2p0] %x[w2p0]",  data[0], data[1], data[2], data[3], data[4], data[5]);
 
will do it.
 
Trz
 
 
Message 4 of 6
(6,112 Views)
Will this produce upper-case hex characters? I couldn't see from the Fmt() help files how to solve this part of the original problem.
 
JR
0 Kudos
Message 5 of 6
(6,106 Views)

Hi,

 

The Uppercase thing can be solved by using :

 

stringUpperCase(ReadBuffer);

 

 

Message 6 of 6
(6,079 Views)