Difference between revisions of "Template:Binary/sandbox"

From blackwiki
Jump to navigation Jump to search
imported>Waiwai933
(Created page with '<includeonly>{{#ifeq:{{#expr: {{{1}}} > 131071}} | 1 |N/A|<!-- -->{{#switch:{{#expr: ({{{1}}} div 131072) mod 2}}|0={{#ifeq:{{#expr: {{{1}}} >262143}} | 1 |0}}|1=1}...')
 
imported>Toohool
(Lua implementation of the template)
Line 1: Line 1:
<includeonly>{{#ifeq:{{#expr: {{{1}}} > 131071}} | 1 |N/A|<!--
+
<includeonly>{{#invoke: BaseConvert | convert | n={{{1}}} | base=2 }}<sub>2</sub></includeonly><noinclude>{{documentation}}</noinclude>
-->{{#switch:{{#expr: ({{{1}}} div 131072) mod 2}}|0={{#ifeq:{{#expr: {{{1}}} >262143}} | 1 |0}}|1=1}}<!--
 
-->{{#switch:{{#expr: ({{{1}}} div 65536) mod 2}}|0={{#ifeq:{{#expr: {{{1}}} >131071}} | 1 |0}}|1=1}}<!--
 
-->{{#switch:{{#expr: ({{{1}}} div 32768) mod 2}}|0={{#ifeq:{{#expr: {{{1}}} >65535}} | 1 |0}}|1=1}}<!--
 
-->{{#switch:{{#expr: ({{{1}}} div 16384) mod 2}}|0={{#ifeq:{{#expr: {{{1}}} >32767}} | 1 |0}}|1=1}}<!--
 
-->{{#switch:{{#expr: ({{{1}}} div 8192) mod 2}}|0={{#ifeq:{{#expr: {{{1}}} >16383}} | 1 |0}}|1=1}}<!--
 
-->{{#switch:{{#expr: ({{{1}}} div 4096) mod 2}}|0={{#ifeq:{{#expr: {{{1}}} >8191}} | 1 |0}}|1=1}}<!--
 
-->{{#switch:{{#expr: ({{{1}}} div 2048) mod 2}}|0={{#ifeq:{{#expr: {{{1}}} >4095}} | 1 |0}}|1=1}}<!--
 
-->{{#switch:{{#expr: ({{{1}}} div 1024) mod 2}}|0={{#ifeq:{{#expr: {{{1}}} >2047}} | 1 |0}}|1=1}}<!--
 
-->{{#switch:{{#expr: ({{{1}}} div 512) mod 2}}|0={{#ifeq:{{#expr: {{{1}}} >1023}} | 1 |0}}|1=1}}<!--
 
-->{{#switch:{{#expr: ({{{1}}} div 256) mod 2}}|0={{#ifeq:{{#expr: {{{1}}} >511}} | 1 |0}}|1=1}}<!--
 
-->{{#switch:{{#expr: ({{{1}}} div 128) mod 2}}|0={{#ifeq:{{#expr: {{{1}}} >255}} | 1 |0}}|1=1}}<!--
 
-->{{#switch:{{#expr: ({{{1}}} div 64) mod 2}}|0={{#ifeq:{{#expr: {{{1}}} >127}} | 1 |0}}|1=1}}<!--
 
-->{{#switch:{{#expr: ({{{1}}} div 32) mod 2}}|0={{#ifeq:{{#expr: {{{1}}} >63}} | 1 |0}}|1=1}}<!--
 
-->{{#switch:{{#expr: ({{{1}}} div 16) mod 2}}|0={{#ifeq:{{#expr: {{{1}}} >31}} | 1 |0}}|1=1}}<!--
 
-->{{#switch:{{#expr: ({{{1}}} div 8) mod 2}}|0={{#ifeq:{{#expr: {{{1}}} >15}} | 1 |0}}|1=1}}<!--
 
-->{{#switch:{{#expr: ({{{1}}} div 4) mod 2}}|0={{#ifeq:{{#expr: {{{1}}} >7}} | 1 |0}}|1=1}}<!--
 
-->{{#switch:{{#expr: ({{{1}}} div 2) mod 2}}|0={{#ifeq:{{#expr: {{{1}}} >3}} | 1 |0}}|1=1}}<!--
 
-->{{#switch:{{#expr: ({{{1}}} div 1) mod 2}}|0=0|1=1}}<sub>2</sub>}}</includeonly>
 
<noinclude>
 
 
 
{{template sandbox notice}}
 
</noinclude>
 

Revision as of 01:07, 23 February 2013

50px Template documentation[view] [edit] [history] [purge]

This template is for quickly converting a decimal number to binary.

Usage

Use {{Binary|x|y}} where x is the decimal number and y is the decimal precision (positive numbers, defaults displays up to 10 digits following the binary point).

Examples:

Code Result Notes
{{Binary|128892}} 111110111011111002 Regular integer
{{Binary|73.3333333|5}} 1001001.010102 Truncated decimal
{{Binary|73.3333333|0}} 10010012 Truncated at decimal point
{{Binary|73|5}} 1001001.000002 Decimals padded to integer
{{Binary|73.25}} 1001001.012 Auto truncation
{{Binary|73.25|4}} 1001001.01002 Decimals padded
{{Binary|{{#expr:1+3/8}}}} 1.0112 Expression support

See also