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

Subversion Repositories yahamm

[/] [yahamm/] [trunk/] [sw/] [calc_nparity_bits.sh] - Blame information for rev 8

Details | Compare with Previous | View Log

Line No. Rev Author Line
1 8 ndesimone
#!/bin/sh
2
#
3
# Print out the minimum number of parity bits needed for the Hamming
4
# code for a given message length.
5
#
6
# For usage call it --help.
7
 
8
help="Usage: $0 [-n] <message_length>\n-n: no extra parity bit"
9
 
10
if [ $1 = "--help" ] || [ $1 = "-h" ]; then
11
    echo -e $help
12
    exit
13
fi
14
 
15
if [ $1 = "-n" ]; then
16
    if [ -z ${2+x} ]; then
17
        echo -e $help
18
        exit
19
    fi
20
 
21
    EXTRA_PARITY_BIT=0
22
    MESSAGE_LENGTH=$2
23
else
24
    if [ -z ${1+x} ]; then
25
        echo -e $help
26
        exit
27
    fi
28
 
29
    EXTRA_PARITY_BIT=1
30
    MESSAGE_LENGTH=$1
31
fi
32
 
33
r=0
34
while [ true ]; do
35
    if [ $((2**r - r - 1)) -ge $MESSAGE_LENGTH ]; then
36
        echo $((r+EXTRA_PARITY_BIT))
37
        exit
38
    fi
39
 
40
    r=$((r+1))
41
done

powered by: WebSVN 2.1.0

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