TAP protocol checksum issue

Here is a strange one. It’s been driving me nuts for a day or so. I’m trying to write an interface for a paging terminal that accepts message in TAP format. Part of the message string includes a 7 bit checksum. A nice explenation is located here: https://everything2.com/title/Telocator+Alphanumeric+Protocol

The only part giving me grief is the checksum. I’ve duplicated their example and the result is never correct. I’m probably missing something stupid. I’ve search all over and so far no one seems to have done this in PowerShell.

The process is pretty simple, take a line of text, do a 7 bit binary conversion, convert that to a decimal value, add it together and get a sum. Take that sum and convert it into a 3 character checksum. This is all outlined in the previously noted link and in the protocol specification here: https://www.telemessage.com/developer/wp-content/uploads/2014/11/TAP-1.8.pdf

Here is the part of the code giving me issues. I broke it out into just the checksum code:

$sum = 379
Write-Host “The sum is:” $sum -ForegroundColor cyan
Write-host ‘The checksum should be “17;”‘`n
$sum = [int]$sum
$d3 = 48 + $sum – ([int]($sum / 16)) * 16
$sum = [int]($sum / 16)
write-host “sum = $sum      d3 = $d3”
$d2 = 48 + $sum – ([int]($sum / 16)) * 16
$sum = [int]($sum / 16)
write-host “sum = $sum      d2 = $d2”
$d1 = 48 + $sum – ([int]($sum / 16)) * 16
write-host “sum = $sum      d1 = $d1”
write-host ”             : $d1 $d2 $d3″
$checksum =[string]([CHAR]$d1)+[string]([char]$d2)+[string]([char]$d3)
write-host “Checksum     : ” -ForegroundColor Yellow -NoNewline
Write-host $checksum -ForegroundColor Cyan
The "sum" is taken from their example, 379. That should produce a checksum value of "17;". By juggling the formulas I get a lot of different things, mostly "2(+", which seems to be what it wants to produce. Any thoughts or suggestions will be appreciated.
I'm using Windows 10 with PS v 7.0.3.


The notes for the example BASIC program explain the behaviour expected from using INT - ‘returns the integer portion of a number’. Using [int] in PowerShell leads to the result being rounded. Use [math]::truncate to achieve the result you need. I was able to obtain the correct checksum using this method.



Thanks Stuart,

I’ll give that a try as soon as I can get back to fighting that particular fire…