Two's complement: Difference between revisions

no edit summary
No edit summary
Line 305:
=={{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.
=={{header|M2000 Interpreter}}==
 
<syntaxhighlight lang="m2000 interpreter">
Module Complement2{
// we use binary.and to get a number in range of byte 0 to 255
byte k=100, z=binary.and(binary.not(k)+1, 0xFF)
print z=156 // z is type of byte always positive
// sint() get an unsigned value and return a signed one with same bits
print sint(z+0xFFFFFF00)=-100 // using 4bytes, we add unsinged 0xFFFFFF00
print sint(z,1)=-100 // using only one byte
}
Complement2
</syntaxhighlight>
{{out}}
<pre>
True
True
True
</pre>
 
=={{header|Nim}}==
404

edits