Question Authors' Forum

How to display the binary form of digital template parameters in the question text?

Re: How to display the binary form of digital template parameters in the question text?

by Hongchuan Liu -
Number of replies: 0
{% set ndecimal = random(15, 20) %}
{% set n = ndecimal %}
{% set binary = "" %}
{% for i in range(0, 15) %}
{%    if n >0 %}
{%        set binary = (n % 2) ~ binary %}
{%        set n = n // 2 %}
{%     endif %}
{% endfor %}
{ "num":"{{ ndecimal }}","bin":"{{binary}}"}

I put the above  in the template parameters and it works well. 

Thanks a lot.