#!/usr/bin/env ruby a = "PUBX,41,1,0007,0003,19200,0" b0 = "PUBX,41,0,0007,0001,115200,1" b1 = "PUBX,41,1,0007,0001,115200,1" b2 = "PUBX,41,2,0007,0001,115200,1" c = "PUBX,41,0,0007,0001,57600,0" def ex_or(a, b); return a ^ b; end def checksum(array) res = array.shift while(array.size > 0) res = ex_or(res, array.shift) end return res end p checksum(a.unpack("c*")).to_s(16) p checksum(b0.unpack("c*")).to_s(16) p checksum(b1.unpack("c*")).to_s(16) p checksum(b2.unpack("c*")).to_s(16) p checksum(c.unpack("c*")).to_s(16)