Binary digits: Difference between revisions

Content added Content deleted
(→‎dt: add)
Line 2,077: Line 2,077:
9000: 10001100101000
9000: 10001100101000
</pre>
</pre>

=={{header|dt}}==
<syntaxhighlight lang="dt">[dup 1 gt? [dup 2 % swap 2 / loop] swap do?] \loop def

[\loop doin rev \to-string map "" join] \bin def

[0 1 2 5 50 9000] \bin map " " join pl</syntaxhighlight>
{{out}}
<pre>0 1 10 101 110010 10001100101000</pre>

=={{header|Dyalect}}==
=={{header|Dyalect}}==


A default <code>ToString</code> method of type <code>Integer</code> is overriden and returns a binary representation of a number:
A default <code>ToString</code> method of type <code>Integer</code> is overridden and returns a binary representation of a number:


<syntaxhighlight lang="dyalect">func Integer.ToString() {
<syntaxhighlight lang="dyalect">func Integer.ToString() {
Line 2,094: Line 2,104:
print("5 == \(5), 50 = \(50), 1000 = \(9000)")</syntaxhighlight>
print("5 == \(5), 50 = \(50), 1000 = \(9000)")</syntaxhighlight>

{{out}}
{{out}}

<pre>5 == 101, 50 = 110010, 1000 = 10001100101000</pre>
<pre>5 == 101, 50 = 110010, 1000 = 10001100101000</pre>

=={{header|EasyLang}}==
=={{header|EasyLang}}==