Two's complement: Difference between revisions
Content added Content deleted
Thundergnat (talk | contribs) m (→{{header|Raku}}: typo) |
|||
Line 91: | Line 91: | ||
=={{header|Julia}}== |
=={{header|Julia}}== |
||
In Julia as in C, if a number n is any integer type, then -n is the two's complement of n, with type preserved. This is true even if n is unsigned. |
In Julia as in C, if a number n is any integer type, then -n is the two's complement of n, with type preserved. This is true even if n is unsigned. |
||
=={{header|Phix}}== |
|||
=== inline assembly === |
|||
<!--<lang Phix>--> |
|||
<span style="color: #008080;">without</span> <span style="color: #008080;">js</span> |
|||
<span style="color: #004080;">integer</span> <span style="color: #000000;">a</span> <span style="color: #0000FF;">=</span> <span style="color: #000000;">0b000011</span><span style="color: #0000FF;">,</span> |
|||
<span style="color: #000000;">a2c</span> |
|||
#ilASM{ |
|||
[32] |
|||
mov eax,[a] |
|||
neg eax |
|||
mov [a2c],eax |
|||
[64] |
|||
mov rax,[a] |
|||
neg rax |
|||
mov [a2c],rax |
|||
} |
|||
<span style="color: #7060A8;">printf</span><span style="color: #0000FF;">(</span><span style="color: #000000;">1</span><span style="color: #0000FF;">,</span><span style="color: #008000;">"%032b -> %032b\n"</span><span style="color: #0000FF;">,{</span><span style="color: #000000;">a</span><span style="color: #0000FF;">,</span><span style="color: #000000;">a2c</span><span style="color: #0000FF;">})</span> |
|||
<!--</lang>--> |
|||
{{out}} |
|||
<pre> |
|||
00000000000000000000000000000011 -> 11111111111111111111111111111101 |
|||
</pre> |
|||
=== normal hll === |
|||
<!--<lang Phix>(phixonline)--> |
|||
<span style="color: #008080;">with</span> <span style="color: #008080;">javascript_semantics</span> |
|||
<span style="color: #004080;">integer</span> <span style="color: #000000;">a</span> <span style="color: #0000FF;">=</span> <span style="color: #000000;">0b000011</span> |
|||
<span style="color: #7060A8;">printf</span><span style="color: #0000FF;">(</span><span style="color: #000000;">1</span><span style="color: #0000FF;">,</span><span style="color: #008000;">"%032b -> %032b\n"</span><span style="color: #0000FF;">,{</span><span style="color: #000000;">a</span><span style="color: #0000FF;">,-</span><span style="color: #000000;">a</span><span style="color: #0000FF;">})</span> |
|||
<!--</lang>--> |
|||
Same output (naturally the rhs is twice as long under 64 bit, in both cases) |
|||
=={{header|PL/M}}== |
=={{header|PL/M}}== |