Jump to content

Binary coded decimal: Difference between revisions

m
arithmetic
m (arithmetic)
Line 206:
println("$test encoded is $enc, decoded is $dec")
end
 
println("BCD 19 ($(bcd_encode(19)[1]) + BCD 1 ($(bcd_encode(1))[1])= BCD 20 " *
"($(bcd_encode(bcd_decode(bcd_encode(19)...) + bcd_decode(bcd_encode(1)...))))")
println("BCD 30 ($(bcd_encode(30)[1]) - BCD 1 ($(bcd_encode(1))[1])= BCD 29 " *
"($(bcd_encode(bcd_decode(bcd_encode(30)...) - bcd_decode(bcd_encode(1)...))))")
println("BCD 99 ($(bcd_encode(99)[1]) + BCD 1 ($(bcd_encode(1))[1])= BCD 100 " *
"($(bcd_encode(bcd_decode(bcd_encode(99)...) + bcd_decode(bcd_encode(1)...))))")
</lang>{{out}}
<pre>
Line 218 ⟶ 225:
9.9999 encoded is (UInt8[0x09, 0x99, 0x99], 1.0, 4), decoded is 9.9999
1.234243670089e8 encoded is (UInt8[0x01, 0x23, 0x42, 0x43, 0x67, 0x00, 0x89], 1.0, 4), decoded is 1.234243670089e8
BCD 19 (UInt8[0x19] + BCD 1 ((UInt8[0x01], 1)[1])= BCD 20 ((UInt8[0x20], 1))
BCD 30 (UInt8[0x30] - BCD 1 ((UInt8[0x01], 1)[1])= BCD 29 ((UInt8[0x29], 1))
BCD 99 (UInt8[0x99] + BCD 1 ((UInt8[0x01], 1)[1])= BCD 100 ((UInt8[0x01, 0x00], 1))
</pre>
 
 
=={{header|Pascal}}==
4,105

edits

Cookies help us deliver our services. By using our services, you agree to our use of cookies.