16 bit checksum calculation I need to calculate checksum using 16-bit ones' complement addition:

while(byte&gt;0)  //len = Total num of bytes
{
    Word = ((Buf[i]&lt;&lt;8) + Buf[i+1]) + Checksum; //get two bytes at a time and  add previous calculated checsum value

    Checksum = Word &amp; 0x0FFFF; //Discard the carry if any

    Word = (Word&gt;&gt;16);     //Keep the carryout for value exceeding 16 Bit

    Checksum = Word + Checksum; //Add the carryout if any

    len -= 2; //decrease by 2 for 2 byte boundaries
    i += 2;
}

 Checksum = (unsigned int)~Checksum;


The above code works fine, and if I understood the concept well (to add 16 bits), add the carry if any and then take the compliment.

Are there any improvements or corrections?
If the packet size is less than 32k words, then you do not need to add the carry until the end:

while(byte&gt;0)  //len = Total num of bytes
{
    Checksum = ((Buf[i]&lt;&lt;8) + Buf[i+1]) + Checksum; //get two bytes at a time and  add previous calculated checsum value

    len -= 2; //decrease by 2 for 2 byte boundaries
    i += 2;
}

 Checksum = (Checksum&gt;&gt;16) + Checksum; //Add the carryout

 Checksum = (unsigned int)~Checksum;