OpenCores
URL https://opencores.org/ocsvn/yahamm/yahamm/trunk

Subversion Repositories yahamm

[/] [yahamm/] [trunk/] [sw/] [calc_nparity_bits.sh] - Rev 8

Compare with Previous | Blame | View Log

#!/bin/sh
#
# Print out the minimum number of parity bits needed for the Hamming
# code for a given message length.
#
# For usage call it --help.
 
help="Usage: $0 [-n] <message_length>\n-n: no extra parity bit"
 
if [ $1 = "--help" ] || [ $1 = "-h" ]; then
    echo -e $help
    exit
fi
 
if [ $1 = "-n" ]; then
    if [ -z ${2+x} ]; then
	echo -e $help
	exit
    fi
 
    EXTRA_PARITY_BIT=0
    MESSAGE_LENGTH=$2
else
    if [ -z ${1+x} ]; then
	echo -e $help
	exit
    fi
 
    EXTRA_PARITY_BIT=1
    MESSAGE_LENGTH=$1
fi
 
r=0
while [ true ]; do
    if [ $((2**r - r - 1)) -ge $MESSAGE_LENGTH ]; then
	echo $((r+EXTRA_PARITY_BIT))
	exit
    fi
 
    r=$((r+1))
done
 

Compare with Previous | Blame | View Log

powered by: WebSVN 2.1.0

© copyright 1999-2024 OpenCores.org, equivalent to Oliscience, all rights reserved. OpenCores®, registered trademark.