Binary coded decimal: Difference between revisions
Content added Content deleted
m (→{{header|J}}) |
(added Free Pascal) |
||
Line 115: | Line 115: | ||
25 |
25 |
||
NB. ...</lang> |
NB. ...</lang> |
||
=={{header|Pascal}}== |
|||
==={{header|Free Pascal}}=== |
|||
There exist a special unit for BCD, even with fractions.Obvious for Delphi compatibility. |
|||
<lang pascal>program CheckBCD; |
|||
// See https://wiki.freepascal.org/BcdUnit |
|||
{$IFDEF FPC} {$MODE objFPC}{$ELSE} {$APPTYPE CONSOLE} {$ENDIF} |
|||
uses |
|||
sysutils,fmtBCD {$IFDEF WINDOWS},Windows{$ENDIF} ; |
|||
{type |
|||
TBcd = packed record |
|||
Precision: Byte; |
|||
SignSpecialPlaces: Byte; |
|||
Fraction: packed array [0..31] of Byte; |
|||
end;} |
|||
var |
|||
Bcd0,Bcd1,BcdOut : tBCD; |
|||
Begin |
|||
Bcd1 := IntegerToBcd(1); |
|||
// 0x19 + 1 = 0x20 |
|||
Bcd0 := IntegerToBcd(19); |
|||
BcdAdd(Bcd0,Bcd1,BcdOut); |
|||
writeln(BcdToStr(Bcd0),'+',BcdToStr(Bcd1),' =',BcdToStr(BcdOut)); |
|||
// 0x30 - 1 = 0x29 |
|||
Bcd0 := IntegerToBcd(29); |
|||
BcdAdd(Bcd0,Bcd1,BcdOut); |
|||
writeln(BcdToStr(Bcd0),'+',BcdToStr(Bcd1),' =',BcdToStr(BcdOut)); |
|||
// 0x99 + 1 = 0x100 |
|||
Bcd0 := IntegerToBcd(99); |
|||
BcdAdd(Bcd0,Bcd1,BcdOut); |
|||
writeln(BcdToStr(Bcd0),'+',BcdToStr(Bcd1),' =',BcdToStr(BcdOut)); |
|||
BcdMultiply(Bcd0,Bcd0,BcdOut); |
|||
writeln(BcdToStr(Bcd0),'*',BcdToStr(Bcd0),' =',BcdToStr(BcdOut)); |
|||
end.</lang> |
|||
{{out}} |
|||
<pre>19+1 =20 |
|||
29+1 =30 |
|||
99+1 =100 |
|||
99*99 =9801 |
|||
</pre> |
|||
=={{header|Wren}}== |
=={{header|Wren}}== |
||
{{libheader|Wren-check}} |
{{libheader|Wren-check}} |