Log in om je oplossingen te testen.
De deadline voor deze oefening is om 17:15, wat over minder dan 5 minuten is.
De deadline voor deze oefening was om 2020-08-21 17:15. Je kan nog steeds indienen, maar de lesgever houdt er mogelijk geen rekening meer mee.
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)
CURRENT_DECIMAL=$(( (CURRENT_DECIMAL | CURRENT_VAL) << 2 ))
done
CURRENT_VAL=$(readLSB2 $(( IDX * 4 )) $FILE)
CURRENT_DECIMAL=$(( (CURRENT_DECIMAL | CURRENT_VAL) ))
echo "$CURRENT_DECIMAL"
}
Je kunt zo vaak indienen als je wenst. Er wordt enkel rekening gehouden met je laatst ingediende oplossing.
Log in om je oplossingen te testen.