Incidentally, IIRC, bit value of -40 is 11011000 because
two's-complement is used to represent negative numbers.

40 = 0010 1000
1101 0111 <- one's-complement
1 <- add 1 for two's-complement
-40 = 1101 1000 <- two's-complement of 40 is -40
D 8 <- D8 is EBCDIC 'Q'

I think... ;-)


-----Original Message-----
[] On
Behalf Of Elvis Budimlic
Sent: Friday, November 09, 2007 4: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.


Celebrating 10-Years of SQL Performance Excellence on IBM i5/OS and

-----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)
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?

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,
or email: C400-L-request@xxxxxxxxxxxx
Before posting, please take a moment to review the archives at

As an Amazon Associate we earn from qualifying purchases.

This thread ...


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

This mailing list archive is Copyright 1997-2021 by 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].

Operating expenses for this site are earned using the Amazon Associate program and Google Adsense.