From Friday, April 19th (11:00 PM CDT) through Saturday, April 20th (2:00 PM CDT), 2024, ni.com will undergo system upgrades that may result in temporary service interruption.
We appreciate your patience as we improve our online experience.
From Friday, April 19th (11:00 PM CDT) through Saturday, April 20th (2:00 PM CDT), 2024, ni.com will undergo system upgrades that may result in temporary service interruption.
We appreciate your patience as we improve our online experience.
02-23-2009 07:38 AM
Please help me to solve this problem as the subject description.
Thanks a lot.
02-23-2009 08:09 AM
If you know the exact numbers of elements your string is made of, you can simply use
char msg[64];
int a, b, c, d;
sscanf (msg, "%x,%x,%x,%x", &a, &b, &c, &d);
If your string is dynamically allocated and can hold a variable number of arguments, you will need to operate in a loop, this way:
int i, a[10];
char msg[64];
char *item;
i = 0;
item = strtok (msg, ",");
while (item) {
sscanf (item, "%x", &a[i++]);
item = strtok (NULL, ",");
}
The "%x" operator evaluates a string of hexadecimal digits (0 to 9, a to f) and calculates the corresponding integer number. This number can be lately represented in hex, decimal, octal or binary format while keeping the same exact value (0xA0 can be represented as decimal 160, octal 240 or binary 10100000)
04-13-2009 05:17 PM
Roberto,
Have any idea how to do the above example if there are no delimiters in the hex string?
such "A0000BC0"
Thanks
Diego
04-13-2009 11:45 PM
Supposing 'a' is your string, you could scan it in a loop for example this way:
for (i = 0; i < strlen(a) / 2; i++) {
Scan (a, "%s[i*w2]>%i[r16]", i * 2, &item);
}
Look in the help for Scan function in the Formatting and I/O Library for an explanation of how the asterisk is used in this formula.
04-14-2009 12:24 AM
04-14-2009 01:28 PM
Eren,
Interesting idea which I had not considered.
Roberto,
U rok ! Alot cleaner than my solution.
Thx
Diego