aaahhh. I got -40. Just did not think about ignore the sign. I think
the reason it is coded that way is to convert a hex character code into
a numeric number. Since '9'-'0' would give you '9'. Slick but
confusing for RPG programmer like me.
thanks
-----Original Message-----
From: c400-l-bounces+lim.hock-chai=usamobility.com@xxxxxxxxxxxx
[mailto:c400-l-bounces+lim.hock-chai=usamobility.com@xxxxxxxxxxxx] On
Behalf Of Elvis Budimlic
Sent: Friday, November 09, 2007 3:25 PM
To: 'C programming iSeries / AS400'
Subject: Re: [C400-L] subtract two char value?
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 is the C programming iSeries / AS400 (C400-L) mailing list To post
a message email: C400-L@xxxxxxxxxxxx To subscribe, unsubscribe, or
change list options,
visit:
http://lists.midrange.com/mailman/listinfo/c400-l
or email: C400-L-request@xxxxxxxxxxxx
Before posting, please take a moment to review the archives at
http://archive.midrange.com/c400-l.
As an Amazon Associate we earn from qualifying purchases.