Skip to content

Commit

Permalink
Making the crc16 calculation a function.
Browse files Browse the repository at this point in the history
  • Loading branch information
onslauth committed Mar 30, 2013
1 parent 98e69a5 commit 8a264e6
Showing 1 changed file with 8 additions and 2 deletions.
10 changes: 8 additions & 2 deletions crc16-table.sh
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,9 @@

# For testing purposes, an input of "123456789" should produce a crc of 0xBB3D

function calc_crc16( )
{

poly=0x8005

declare -a crc_16_table=(
Expand Down Expand Up @@ -51,7 +54,10 @@ do
crc=$(( crc_16_table[ ( crc ^ buf ) & 0xff ] ^ ( crc >> 8 ) ))
done

echo "crc: $crc"
printf "crc: 0x%04X\n" $crc
printf "%04x" $crc

}

crc16=$( calc_crc16 "$1" )
echo "crc16: $crc16"

0 comments on commit 8a264e6

Please sign in to comment.