function getCheckSum(payload) { var checkSum = 0; for (i = 0; i < payload.length-1; i++) { checkSum = checkSum + parseInt(payload[i]); } return checkSum&0xff; } var cmd= [0xFF,0x55,0x04,0xa8,0x0f,0x00,0x00,0x0f]; checkSum=getCheckSum(cmd) console.log(checkSum.toString(16))