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
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.
Celebrating 10-Years of SQL Performance Excellence on IBM i5/OS and OS/400
Subject: [C400-L] subtract two char value?
I ran into code below and confuse about the line where it subtract two
unsigned int Hex2Int(char cC)
default:return(cC-'0');break; <== What is this mean? How can C
subtract two char values?
I wrote a test program below and the result of 'H'-'0' is 'Q'. Huh?
cC = 'H';
result = cC-'0';
As an Amazon Associate we earn from qualifying purchases.