LabWindows/CVI

cancel
Showing results for 
Search instead for 
Did you mean: 

ascii to hex

What is the best way to convert a ascii to hex or decimal?
Below I take the two returned values and concatenate the the second byte of the first hex value to the first two bytes for the second returned values. Then I need to take the return value of "194" string(hex value) and convert is back to decimal format.
My decimal value 194(hex) to 404(decimal)?
 
Currently I am using a NI DAQ 6534 unit that returns all value into a decimal format(16 bit).
 
#include <ansi_c.h>
#include <formatio.h>
#include <utility.h>
#include <cvirte.h>
  int HEX = 62677;
  int HEX1 = 6432;

 unsigned char read_data[8];
 unsigned char read_data1[8];
int main (int argc, char *argv[])
{
 if (InitCVIRTE (0, argv, 0) == 0)
  return -1;    /* out of memory */
 

 Fmt (read_data, "%s<%x", HEX);//i is the index location, w is the width in bytes
 Fmt (read_data1, "%s<%x", HEX1);//i is the index location, w is the width in bytes
 Fmt (read_data, "%s<%s[i1w1]", read_data);//i is the index location, w is the width in bytes
 Fmt (read_data1, "%s<%s[i0w2]", read_data1);//i is the index location, w is the width in bytes
 strncat (read_data1,read_data, 2);
 
 Delay(1);

 return 0;
}

Message Edited by chinook on 02-12-2006 08:33 AM

0 Kudos
Message 1 of 3
(5,110 Views)

The "%x" modifier scans a string extracting the decimal values considering the source string expresses numbers in hex format. It scans strings containing "0" to "9" and "A" to "F" digits, with or without an optional "0x" prefix.

strcpy (a, "194");
sscanf (a, "%x", &b);     // b = 404 (decimal)



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?
Message 2 of 3
(5,104 Views)
Roberto Bozzolo
 
 
 
That is great. Due to my job of working with production issues and doing test development its great to have people like you to help other people with your experience.
 
The one issue we are having as of right know is working with the NI DAQ 6534 in conjunction with the waveform generator( Learning curve). One thing I did learn is the impedence matching issues. We had problems with ringing on outputs that were used as control lines. Had to add a 130 ohm resistor in line with the control lines.
 
 
Thanks for your help!
Chinook(Ron)
0 Kudos
Message 3 of 3
(5,089 Views)