Back to Blog
C string to bcd6/15/2023 ( TOBCD 1, TOBCD 23, TOBCD 45, TOBCD 67, TOBCD 89, TOBCD 01 ) # use the 2-digit BCD to add/subtract larger numbers # Print( ( IF carry OF r THEN "1" ELSE "" FI, TOSTRING r, newline ) ) Print( ( TOSTRING ( TOBCD 30 - bcd 1 ), newline ) ) Print( ( TOSTRING ( TOBCD 19 + bcd 1 ), newline ) ) OP -:= ( REF BCD a, BCD b )REF BCD: a := a - b OP +:= ( REF BCD a, BCD b )REF BCD: a := a + b # returns the difference of a and b, a and b can be positive or negative # OP - = ( BCD a )BCD: BCD( - value OF a, carry OF a ) # returns the value of b negated, carry is preserved # ![]() THEN # different signs, magnitude of a at least that of b #ĮLSE # result is negative - tens complement #īCD result := ( bcd 99 + ASBCD bcd value ) + bcd 1 OP TOSTRING = ( BCD a )STRING: IF value OF a = 0, bp = value OF b >= 0 ![]() # returns a two-digit string representation of the BCD value a # # returns a converted to BCD format, truncating and setting carry # # if the value has overflowed, it is truncated to a valid value and # # constructs a BCD value from a, assuming it is in the correct format # ![]() , BOOL carry # TRUE if the value overflowed, # MODE BCD = STRUCT( INT value # BCD value - signed -x99 to x99 # INT x99 = ( 9 * 16 ) + 9 # maximum unsigned 2-digit BCD value # ![]() BEGIN # implements packed BCD arithmetic #
0 Comments
Read More
Leave a Reply. |