Shouldn't it be: (comments removed)
char* y;
switch (y[0]) {
case 0x002D:
value[0] = '2';
value[1] = 'D';
break;
default:
value[0] = 'X';
value[1] = 'X';
break;
}
Btw, if you are converting all values from 0x00 to 0xff, your switch
statement would be very long since you have a case test for each value. So
you would have 256 case statements.
I usually use this:
char *hexdigits = "0123456789ABCDEF";
...
value[0] = hexdigits[y[0] >> 4];
value[1] = hexdigits[y[0] & 0xf];
...
Eg, This will print the hex values of the characters in the string y.
main()
{
char *hexdigits = "0123456789ABCDEF";
char str[3] = "\0\0\0";;
int i;
char *y = "The quick brown fox jumps over the lazy dog";
for (i = 0; i < strlen(y); i++) {
str[0] = hexdigits[y[i] >> 4];
str[1] = hexdigits[y[i] & 0xf];
printf("%s ", str);
}
printf("\n");
}
Hope this helps.
Rgds
Alvin
On 26/2/03 9:16 PM, "Conrad Spiteri" <[EMAIL PROTECTED]> wrote:
> Hi All,
> I am writing an application which receives data from
> the IR port (which in turn is stored in a buffer) and
> then the Palm (Running OS 3.5) interprets and executes
> the received commands.
>
> The data I receive in hex and is then converted to
> specific characters by a switch/case routine. Hence
> the hex data 0x002D would be converted as follows:
> // Part of the program
>
> char* y;
> switch (y[0])
> // the rest of the values
> case 0x002D:
> {
> value[0] = '2';
> value[1] = 'D';
> break;
> }
> // the rest of the values
> default:
> {
> value[0] = 'X';
> value[1] = 'X';
> break;
> }
> However, I am getting the XX value every now and then,
> when it should never happen as I am covering all the
> values from 0x0000 to 0x00FF.
> I have noted that when this happens 2 values are being
> sent in 1 hex format (eg. 0x06D1) instead of one
> containing 0x0006 and another containing 0x00D1.
>
> Any ideas on how I should convert the 0x06D1 to 2 hex
> digits as above, or is this a wrong approach to
> transposing this data?
>
> Any help would be greatly appreciated, as I am still a
> novice at this stuff!!
> Thank you for your time!
> Conrad.
>
>
> __________________________________________________
> Do You Yahoo!?
> Everything you'll ever need on one web page
> from News and Sport to Email and Music Charts
> http://uk.my.yahoo.com
--
For information on using the Palm Developer Forums, or to unsubscribe, please see
http://www.palmos.com/dev/support/forums/