Warning! You are viewing this exercise in a course that you are not a member of. You won't appear on your teacher's scoresheets until you register.
Sign in to test your solution.
The deadline for this exercise was at 2020-08-21 17:15. You can still submit, but your submissions may not be accounted for.
decToChar () {
# converts single-byte decimal value to equivalent character
# arg: decimal number from 0-255
# out: one character
echo -n -e "\x$(printf %02X "$1")"
}

readDecimal() {
# Read the n'th decimal from a file. This function looks at the 2 least significant bits of 4 consecutive bytes in
# the given file and pastes them together to decode the decimal.
# arg1: decimal offset
# arg2: filename from which the given decimal should be read and decoded.

readcharDec () {
# read one character from file & convert to equivalent decimal value
# arg1: offset (# of bytes to skip before reading)
# arg2: filename
# out: decimal value from 0-255
VAL=$(xxd -p -l1 -s $1 $2)
printf %d "0x$VAL"
}

readLSB2 () {
# read the 2 LSB's from the byte at the given position in the given file.
# arg1: byte offset
# arg2: filename
READ_BYTE=$(readcharDec $1 $2)
echo $(( READ_BYTE & 3 ))
}

CURRENT_DECIMAL=0
IDX=$1
FILE=$2

for ((j = 3; j > 0; j--)); do
CURRENT_VAL=$(readLSB2 $(( IDX * 4 + j )) $FILE)
You can submit as many times as you like. Only your latest submission will be taken into account.
Sign in to test your solution.