We have a course that includes the conversion of binary to decimal and vice versa. Setting up a Formula Question for the binary to decimal was easy:

**Question**: Convert the binary number [bit8][bit7][bit6][bit5][bit4][bit3][bit2][bit1] to decimal.**Variable Definitions**:

Variable | Min | Max | Decimal Places |

bit8 | 0 | 1 | 0 |

bit7 | 0 | 1 | 0 |

bit6 | 0 | 1 | 0 |

bit5 | 0 | 1 | 0 |

bit4 | 0 | 1 | 0 |

bit3 | 0 | 1 | 0 |

bit2 | 0 | 1 | 0 |

bit1 | 0 | 1 | 0 |

**Formula Definition**: bit8*128+bit7*64+bit6*32+bit5*16+bit4*8+bit3*4+bit2*2+bit1

However, reversing this question is much more difficult because there is now "flat" formula capable to determining the binary of a decimal.

Is it possible to make a recursive formula in Canvas that could be used to this end? If so, how? I couldn't find anything in the documentation on setting up a complex formula.

Christopher,

If you want them to give you any number that is padded with 0's, then no, it cannot be done. The reason is that Canvas formula questions require you to enter a decimal number as an answer. Although Ruby supports binary numbers like 0b00011011, Canvas will not accept that and converts it to 0.

If you enter enter 01111, Canvas drops the leading 0 and treats it as 1111 (decimal).

However, if you're willing to allow 111 as an answer for decimal 7 (as opposed to 00000111) then yes, you can do it with a formula question.

If your question is:

Enter [x] in binary, then you could use the following:It's not fancy and it only allows up to 8 digit binary numbers (0-255 decimal), but it works. If I did happen to make a typo, you can figure out what I'm doing and fix it.

Here's another example. Notice there are no leading 0's.

If you absolutely have to have the leading 0's, then I would use something like Excel to generate a bunch of values and import it into Respondus. I would then transfer those over to Canvas as fill in the blank questions and then let students know how many digits they should give as they are entering a string for an answer instead of a number.

To answer your other question, no there is no recursion capability built into Canvas' formula generator.