Hello all, get ready for me having done something pretty daft... I'm trying to get something going with C18: unsigned char [BUFFER_LEN] buffer; unsigned long checksum = 0; unsigned int ip_header_len; unsigned int i = 0; //some code that assigns buffer values and other stuff ... ... for (; i+1 < ip_header_len + IP_OFFSET; i = i+2) { checksum = checksum + buffer[i]*256 + buffer[i+1]; } //now invert checksum = ~checksum; This is a snippit of some code I'm putting together. Basically what it's supposed to do is group two bytes in "buffer" at a time, convert them to a 16bit number, and add them to checksum. Sounds simple? Well, the 16bit stuff works fine, for example, the first two bytes collected from "buffer" are 0x45 and 0x00, after running the for loop once the ICD correctly reports that checksum = 0x00004500. This continues on, until I get to a point where the number is bigger then 16 bits. At that point "checksum" acts like it's a 16bit number, going from say 0x0000fe00 to 0x00001045. Does anyone see something wrong with how I've done things here? Is there something about C or C18 that will "demote" the unsigned long "checksum" (which, according to the C18 manual, unsigned long = 32bits, plus the MPLAB watch window reports it's 32 bits long) from a 32bit value to a 16bit value for this calc? I've confirmed the "wrong" result isn't something the ICD2 does since the outside work also sees the result of the "wrong" value. All optimizations in C18 have been disabled. I've also tried other "lines" like: checksum += buffer[i]*256 + buffer[i+1]; checksum += buffer[i]<<8 + buffer[i+1]; checksum += (unsigned long)(buffer[i]*256 + buffer[i+1]); The interesting thing is after running the checksum = ~checksum line, checksum comes back with it's upper bits flipped (as you'd expect!). i.e. checksum = 0x0000aa55 checksum = ~checksum; -> checksum = 0xffff55aa is what the ICD2 reports Thanks for any clues. TTYL ----------------------------- Herbert's PIC Stuff: http://repatch.dyndns.org:8383/pic_stuff/ -- http://www.piclist.com PIC/SX FAQ & list archive View/change your membership options at http://mailman.mit.edu/mailman/listinfo/piclist