#!/usr/bin/perl use warnings; use strict; use Inline C => <<'END_OF_C_CODE'; #include SV* normalChecksum8(char *b, int n) { int i; uint16_t a, bb; //Sums bytes 1 to n-1 unsigned to a 2 byte value. Sums quotient and //remainder of 256 division. Again, sums quotient and remainder of //256 division. for(i = 1, a = 0; i < n; i++) a+=(uint16_t)b[i]; bb = a / 256; a = (a - 256 * bb) + bb; bb = a / 256; return newSVpvf("%d", (a-256*bb)+bb); } END_OF_C_CODE print normalChecksum8("3532",2). "\n";