Binary coded decimal: Difference between revisions

Content added Content deleted
(Added FreeBasic)
m (→‎{{header|Wren}}: Changed to Wren S/H)
 
Line 1,182: Line 1,182:


In what follows, the hex prefix '0x' is simply a way of representing BCD literals and has nothing to do with hexadecimal as such.
In what follows, the hex prefix '0x' is simply a way of representing BCD literals and has nothing to do with hexadecimal as such.
<syntaxhighlight lang="ecmascript">import "./check" for Check
<syntaxhighlight lang="wren">import "./check" for Check
import "./math" for Int
import "./math" for Int
import "./str" for Str
import "./str" for Str
Line 1,272: Line 1,272:
0x99 + 1 = 0x100 or, in unpacked BCD, 100100001001 + 1 = 10000000000000000
0x99 + 1 = 0x100 or, in unpacked BCD, 100100001001 + 1 = 10000000000000000
</pre>
</pre>

=={{header|Z80 Assembly}}==
=={{header|Z80 Assembly}}==
The <code>DAA</code> function will convert an 8-bit hexadecimal value to BCD after an addition or subtraction is performed. The algorithm used is actually quite complex, but the Z80's dedicated hardware for it makes it all happen in 4 clock cycles, tied with the fastest instructions the CPU can perform.
The <code>DAA</code> function will convert an 8-bit hexadecimal value to BCD after an addition or subtraction is performed. The algorithm used is actually quite complex, but the Z80's dedicated hardware for it makes it all happen in 4 clock cycles, tied with the fastest instructions the CPU can perform.