Char values are int data type, but not really. Only last byte is used and
other leading 3 bytes are ignored.
There is no problem subtracting two ints, as long as it makes sense in your
program.
If you look at the EBCDIC table of values 'H' = 200 and '0' = 240. When you
subtract these two values you get -40. However, bit value of single byte
-40 is 11011000. If you then ignore the sign (as system must do, since it's
unsigned char) and look at it as unsigned byte value, you interpret that bit
mapping as 216. Guess what EBCDIC character is for 216? Yes, it is 'Q'.

Now, why would anyone want to do that... it escapes me.
I'm sure you know the answer from the context of your program.

Elvis

Celebrating 10-Years of SQL Performance Excellence on IBM i5/OS and OS/400
http://centerfieldtechnology.com/training.asp


-----Original Message-----
Subject: [C400-L] subtract two char value?

I ran into code below and confuse about the line where it subtract two
char fields:

unsigned int Hex2Int(char cC)
{
switch(cC)
{
case 'a':return(10);break;
case 'b':return(11);break;
case 'c':return(12);break;
case 'd':return(13);break;
case 'e':return(14);break;
case 'f':return(15);break;
case 'A':return(10);break;
case 'B':return(11);break;
case 'C':return(12);break;
case 'D':return(13);break;
case 'E':return(14);break;
case 'F':return(15);break;
default:return(cC-'0');break; <== What is this mean? How can C
subtract two char values?
}
return(0);
}


I wrote a test program below and the result of 'H'-'0' is 'Q'. Huh?

int main(void)
{
char cC;
char result;
cC = 'H';
result = cC-'0';
}



This thread ...

Follow-Ups:
Replies:

Follow On AppleNews
Return to Archive home page | Return to MIDRANGE.COM home page

This mailing list archive is Copyright 1997-2020 by midrange.com and David Gibbs as a compilation work. Use of the archive is restricted to research of a business or technical nature. Any other uses are prohibited. Full details are available on our policy page. If you have questions about this, please contact [javascript protected email address].