Two's complement: Difference between revisions
m
→{{header|Wren}}: Changed to Wren S/H
(→{{header|Raku}}: fix link) |
m (→{{header|Wren}}: Changed to Wren S/H) |
||
Line 561:
This is illustrated by running the following code:
<syntaxhighlight lang="
a = -a
System.print(a) // -0</syntaxhighlight>
Line 570:
We can therefore emulate how two's complement works on ''signed'' 32 bit integers by using the bitwise complement operator '''~''' to flip the bits as follows:
<syntaxhighlight lang="
var pow31 = 2.pow(31)
var bs = [-pow31, -pow31+1, -2, -1, 0, 1, 2, pow31-2, pow31-1]
|