Two's complement: Difference between revisions

Added Forth entry
(Added Forth entry)
Line 85:
<syntaxhighlight lang="c">int a = 3;
a = -a;</syntaxhighlight>
 
=={{header|Forth}}==
{{works with|gforth|0.7.3}}
Forth uses two's complement internally. One can use the 'base' variable to switch from one base to another.
<syntaxhighlight lang="forth">: 2s'complement base @ swap dup negate swap 2 base ! u. u. base ! ;
25 2s'complement</syntaxhighlight>
 
{{out}}
<pre>11001 1111111111111111111111111111111111111111111111111111111111100111 ok
</pre>
 
 
=={{header|FreeBASIC}}==
7

edits