This Moodle question type supports improved dataset value formatting and answer formatting, including different numeric formats:
- Binary
- Octal
- Decimal
- Hexadecimal
It was modified from the Calculated question type at the University of Wisconsin - Madison by Daniel Seemuth.
To install using git, type this command in the root of your Moodle install:
git clone git://github.com/seemuth/moodle-question_type_calculatedformat.git question/type/calculatedformat
Then add /question/type/calculatedformat to your .gitignore file.
After you install this question type, navigate to /admin/index.php of your Moodle site. This will prompt you to finish installing the question type.
For question text and feedback text, you can format numbers in a variety of ways. Some examples include:
{%x={A}}
means format the wildcard {A} as a hexadecimal integer with as many digits as are needed. E.g., 2AF{%4x={A}}
means format the wildcard {A} as a 4-digit hexadecimal integer. E.g., 02AF{%4x={{A}+{B}}}
means format the sum of wildcards {A} and {B} as a 4-digit hexadecimal integer. E.g., 02AF{%p4x={A}}
means format the wildcard {A} as a 4-digit hexadecimal integer with prefix 0x. E.g., 0x02AF{%p4.3x={A}}
means format the wildcard {A} as a hexadecimal number with 4 integer digits and 3 fractional digits. E.g., 0x02AF.E00{%_16b={A}}
means format the wildcard {A} as a 16-bit binary number with groups of 4 digits separated by the underscore character (_
). E.g., 0011_1010_0000_1111{%p_16b={A}}
means format the wildcard {A} as a 16-bit binary number with groups of 4 digits separated by the underscore character (_
) with prefix 0b. E.g., 0b0011_1010_0000_1111{%p,9o={A}}
means format the wildcard {A} as a 9-digit octal number with groups of 3 digits separated by a comma and with prefix 0o. E.g., 0o012,345,670
Formatting options (which appear between the percent sign and before any length specifiers) include:
p
: show base prefix (0b
,0o
,0d
, or0x
)_
: display in groups of 4 digits separated by_
,
: display in groups of 3 digits separated by,
Length specifiers can be:
- not given: display in as many digits as needed
- NUM: display in at least NUM integer digits if decimal, or display in exactly NUM integer digits if binary, octal, or hexadecimal
- NUM1
.
NUM2: display integer portion in at least NUM1 digits if decimal, or in exactly NUM1 digits if binary, octal, or hexadecimal; followed by exactly NUM2 fractional digits
The base indicator (which appears immediately before the equals sign) can be:
b
for binaryo
for octald
for decimalx
for hexadecimal.
Binary, octal, and hexadecimal numbers are masked to the appropriate number of digits if the number of digits is specified and positive. To display a binary, octal, or hexadecimal number without masking, do not include a digit length. E.g., {%x={A}}
(This Usage Guide is written for Moodle v2.6.)
To use this question type, create or edit a quiz, and choose the "Calculated format" question type.
For example, we will create a question to convert a decimal number between 0 and 10 to binary, fixed-point format:
- Create or edit a quiz. For this example, we will use the "Question behavior" quiz settings of shuffle: yes, interactive with multiple tries.
- Click "Add a question ...".
- Choose "Calculated format".
- Enter a question name, e.g., "Convert decimal to fixed-point binary".
- Enter the question text, e.g., "What is {A} in fixed-point binary format with 4 integer bits and 3 fractional bits? For purposes of testing, the answer should be {%4.3b={A}}.".
- Under "Correct answer base and format":
- Set "Require answers in base" to "Binary (base 2)".
- Set "Require exact number of digits" to "Yes".
- Set "Number of integer digits" to 4.
- Set "Fractional digits" to 3.
- Set "Show base?" to "Show base as subscript."
- Under "Answers":
- Set "Answer 1 formula =" to "{A}".
- Set "Grade" to 100%.
- Set "Tolerance ±" to 0.
- Set tolerance "Type" to "Nominal".
- Click "Save changes".
- Set "Wild card {A}" to "will use a new shared dataset".
- Under "Synchronize the data from shared datasets with other questions in a quiz", choose "Synchronize".
- Click "Next page".
- Under "Add": under "Add item": click "Add".
- Under "Add": under "Add item": click "Add" a second time (after the page reloads).
- Below the "Delete" section, choose 5 "set(s) of wild card(s) values" and click "Display".
- Under "Set 1" and "Set 2", set the "Shared wild card {A}" to 1.25 for one and 6.125 for the other.
- Click "Save changes".
- Preview the quiz. For this question you should see something like:
What is 1.25 in fixed-point binary format with 4 integer bits and 3 fractional bits? For purposes of testing, the answer should be 0001.010.
- Enter "1.010" and click "Check". You should see a message saying, "Incorrect number of digits".
- Enter "0002.010" and click "Check". You should see a message saying, "You must enter a valid number."
- Enter the correct answer and click "Check". Your answer should be marked as correct.