简体   繁体   中英

Migrating script from C to PHP

I'm migrating a script from C to PHP ( http://svn.stellman-greene.com/mgrs_to_utm/trunk/ ) and I have a problem with this concept in mgrs_to_utm.c :

Letters[0] = (toupper(MGRS[j]) - (long)'A');
if ((Letters[0] == LETTER_I) || (Letters[0] == LETTER_O))

MGRS[j] is a part of string, but WTF I can substract a (long)'A' to a LETTER ??

LETTER_I is an integer (defined in mgrs_to_utm.h ).

I have in mind PHP and I can't found the logic to this operation.

Thanks a lot for your help :)

In ASCII, the character 'A' has value 65, so Letters[0] effectively contains an offset into the alphabet (A being 0).

If MGRS[j] is 'I' (73) then we take 'A' (65) from it to leave 8

A B C D E F G H I J K...
0 1 2 3 4 5 6 7 8 9 10

The code is pretty much the same as:

if ( MGRS[j] == 'I' || MGRS[j] == 'O' || MGRS[j] == 'i' || MGRS[j] == 'o')

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM