Template:BinaryDigit

From Wikiversity
Jump to navigation Jump to search

first argument: n
second argument: i

output: digit at place i (with place value 2i) in the binary representation of n

calculation: floor(n / 2^i) % 2


examples
{{BinaryDigit|6|0}}
{{BinaryDigit|6|1}}
{{BinaryDigit|6|2}}
{{BinaryDigit|7|0}}
{{BinaryDigit|7|1}}
{{BinaryDigit|7|2}}
{{BinaryDigit|7|3}}
The least significant bit is on the left!

0 1 1

1 1 1 0

(The error message "Unrecognized punctuation character" below does not matter.)
Expression error: Unrecognized punctuation character "{".