1/n Decimal 2 0.5 4 0.25 8 0.125 16 0.0625 32 0.03125 64 0.015625 128 0.0078125 256 0.00390625 Convert integer to BCD Shift left, if nibble is five or greater, add three, 8 times. Test case 1111 1111 (FFh) 1111 1111 ; 0000 0000 0000 (000) ;start 1111 1110 ; 0000 0000 0001 (001) ;shift left 1111 1100 ; 0000 0000 0011 (003) ;shift left 1111 1000 ; 0000 0000 0111 (007) ;shift left 1111 1000 ; 0000 0000 1010 (00A) ;add 3 1111 0000 ; 0000 0001 0101 (015) ;shift left 1111 0000 ; 0000 0001 1000 (018) ;add 3 1110 0000 ; 0000 0011 0001 (031) ;shift left 1100 0000 ; 0000 0110 0011 (063) ;shift left 1100 0000 ; 0000 1001 0011 (093) ;add 3 1000 0000 ; 0001 0010 0111 (127) ;shift left 1000 0000 ; 0001 0010 1010 (12A) ;add 3 0000 0000 ; 0010 0101 0101 (255) ;shift left Test case 1010 1010 (AAh) 1010 1010 ; 0000 0000 0000 (000) ;start 0101 0100 ; 0000 0000 0001 (001) ;shift left 1010 1000 ; 0000 0000 0010 (002) ;shift left 0101 0000 ; 0000 0000 0101 (005) ;shift left 0101 0000 ; 0000 0000 1000 (008) ;add 3 1010 0000 ; 0000 0001 0000 (010) ;shift left 0100 0000 ; 0000 0010 0001 (021) ;shift left 1000 0000 ; 0000 0100 0010 (042) ;shift left 0000 0000 ; 0000 1000 0101 (085) ;shift left 0000 0000 ; 0000 1011 1000 (0B8) ;add 3 0000 0000 ; 0001 0111 0000 (170) ;shift left Convert fixed-point fractional to BCD MULTIPLY by 10, CONVERT, REPEAT UNTIL FRACTIONAL GONE Test case 0.1111b .1111 * 1010 = 1001.0110 = 9.6h (0.9xxx) (integer portion placed in 'converted' output) .0110 * 1010 = 0011.1100 = 3.Ch (0.93xx) .1100 * 1010 = 0111.1000 = 7.8h (0.937x) .1000 * 1010 = 0101.0000 = 5.0h (0.9375) Test case 0.00000001b .00000001 * 1010 = 0000.00001010 = 0.0Ah (0.0xxxxxxx) .00001010 * 1010 = 0000.01100100 = 0.64h (0.00xxxxxx) .01100100 * 1010 = 0011.11101000 = 3.E8h (0.003xxxxx) .11101000 * 1010 = 1001.00010000 = 9.10h (0.0039xxxx) .00010000 * 1010 = 0000.10100000 = 0.A0h (0.00390xxx) .10100000 * 1010 = 0110.01000000 = 6.40h (0.003906xx) .01000000 * 1010 = 0010.10000000 = 2.80h (0.0039062x) .10000000 * 1010 = 0101.00000000 = 5.00h (0.00390625) Test case 0.11111111b .11111111 * 1010 = 1001.11110110 = 9.F6h (0.9xxxxxxx) .11110110 * 1010 = 1001.10011100 = 9.9Ch (0.99xxxxxx) .10011100 * 1010 = 0110.00011000 = 6.18h (0.996xxxxx) .00011000 * 1010 = 0000.11110000 = 0.F0h (0.9960xxxx) .11110000 * 1010 = 1001.01100000 = 9.60h (0.99609xxx) .01100000 * 1010 = 0011.11000000 = 3.C0h (0.996093xx) .11000000 * 1010 = 0111.10000000 = 7.80h (0.9960937x) .10000000 * 1010 = 0101.00000000 = 5.00h (0.99609375) BCD to bin SHIFT RIGHT 1, IF NIBBLE > 7; SUBTRACT 3, BIT SHIFTED OUT SHIFTED INTO RESULT, 8 times Test case 255 (0010 0101 0101) 0010 0101 0101 -> 0001 0010 1010 ; 1000 0000 (80h) ; Shift right, low nibble over seven 0001 0010 1010 -> 0001 0010 0111 ; 1000 0000 (80h) ; Subtract 3 0001 0010 0111 -> 0000 1001 0011 ; 1100 0000 (C0h) ; Shift right, middle nibble over seven 0000 1001 0011 -> 0000 0110 0011 ; 1100 0000 (C0h) ; Subtract 3 0000 0110 0011 -> 0000 0011 0001 ; 1110 0000 (E0h) ; Shift right, no nibble over seven 0000 0011 0001 -> 0000 0001 1000 ; 1111 0000 (F0h) ; Shift right, low nibble over seven 0000 0001 1000 -> 0000 0001 0101 ; 1111 0000 (F0h) ; Subtract 3 0000 0001 0101 -> 0000 0000 1010 ; 1111 1000 (F8h) ; Shift right, low nibble over seven 0000 0000 1010 -> 0000 0000 0111 ; 1111 1000 (F8h) ; Subtract 3 0000 0000 0111 -> 0000 0000 0011 ; 1111 1100 (FCh) ; Shift right, no nibble over seven 0000 0000 0011 -> 0000 0000 0001 ; 1111 1110 (FEh) ; Shift right 0000 0000 0001 -> 0000 0000 0000 ; 1111 1111 (FFh) ; Shift right Test case 063 (0000 0110 0011) 0000 0110 0011 -> 0000 0011 0001 ; 1000 0000 (80h) ; Shift right 0000 0011 0001 -> 0000 0001 1000 ; 1100 0000 (C0h) ; Shift right, low nibble over seven 0000 0001 1000 -> 0000 0001 0101 ; 1100 0000 (C0h) ; Subtract 3 0000 0001 0101 -> 0000 0000 1010 ; 1110 0000 (E0H) ; Shift right, low nibble over seven 0000 0000 1010 -> 0000 0000 0111 ; 1110 0000 (E0h) ; Subtract 3 0000 0000 0111 -> 0000 0000 0011 ; 1111 0000 (F0h) ; Shift right 0000 0000 0011 -> 0000 0000 0001 ; 1111 1000 (F8h) ; Shift right 0000 0000 0001 -> 0000 0000 0000 ; 1111 1100 (FCh) ; Shift right 0000 0000 0000 -> 0000 0000 0000 ; 0111 1110 (7Eh) ; Shift right 0000 0000 0000 -> 0000 0000 0000 ; 0011 1111 (3Fh) ; Shift right Test case 170 (0001 0111 0000) 0001 0111 0000 -> 0000 1011 1000 ; 0000 0000 (00h) ; Shift right, low and middle nibbles over seven 0000 1011 1000 -> 0000 1000 0101 ; 0000 0000 (00h) ; subtract 3 0000 1000 0101 -> 0000 0100 0010 ; 1000 0000 (80h) ; Shift right 0000 0100 0010 -> 0000 0010 0001 ; 0100 0000 (40h) ; Shift right 0000 0010 0001 -> 0000 0001 0000 ; 1010 0000 (A0h) ; Shift right 0000 0001 0000 -> 0000 0000 1000 ; 0101 0000 (50h) ; Shift right, low nibble over seven 0000 0000 1000 -> 0000 0000 0101 ; 0101 0000 (50h) ; Subtract 3 0000 0000 0101 -> 0000 0000 0010 ; 1010 1000 (A8h) ; Shift right 0000 0000 0010 -> 0000 0000 0001 ; 0101 0100 (54h) ; Shift right 0000 0000 0001 -> 0000 0000 0000 ; 1010 1010 (AAh) ; Shift right BCD Fractional to Fixed Point fractional Left shift BCD fractional, add 6 to nibbles preceding 'overshifted' nibble, correct for out of bounds in upward cascade. Test Case: 0.123 (0000.0001 0010 0011) 0000.0001 0010 0011 > 0000.0010 0100 0110 (0.246) ; 0.0xxx xxxx ;shift, no issues detected, take 0 from output 0000.0010 0100 0110 > 0000.0100 1000 1100 (0.48C) ; 0.0xxx xxxx ;shift, low nibble out of bounds 0000.0100 1000 1100 > 0000.0100 1001 0010 (0.492) ; 0.00xx xxxx ;correct out of bounds, take 0 0000.0100 1001 0010 > 0000.1001 0010 0100 (0.924) ; 0.00xx xxxx ;'overshift' detected 0000.1001 0010 0100 > 0000.1001 1000 0100 (0.984) ; 0.000x xxxx ;correct for overshift, take 0 0000.1001 1000 0100 > 0001.0011 0000 1000 (1.308) ; 0.000x xxxx ;multiple 'overshift' events 0001.0011 0000 1000 > 0000.1001 0110 1000 (0.968) ; 0.0001 xxxx ;add 6 to preceding nibbles and take off 1 from output. 0000.1001 0110 1000 > 0001.0010 1101 0000 (1.2D0) ; 0.0001 xxxx ;multiple overshift events and an out of bounds 0001.0010 1101 0000 > 0001.1000 1101 0110 (1.8D6) ; 0.0001 xxxx ;corrected for overshift 0001.1000 1101 0110 > 0000.1001 0011 0110 (0.936) ; 0.0001 1xxx ;corrected out of bounds, take off 1 from output 0000.1001 0011 0110 > 0001.0010 0110 1100 (1.26C) ; 0.0001 1xxx ;Overshift and out of bounds detected 0001.0010 0110 1100 > 0001.1000 0110 1100 (1.86C) ; 0.0001 1xxx ;corrected for overshift 0001.1000 0110 1100 > 0000.1000 0111 0010 (0.872) ; 0.0001 11xx ;corrected for out of bounds, take off 1 from output 0000.1000 0111 0010 > 0001.0000 1110 0100 (1.0E4) ; 0.0001 11xx ;overshift and out of bounds detected 0001.0000 1110 0100 > 0001.0110 1110 0100 (1.6E4) ; 0.0001 11xx ;Correct for overshift 0001.0110 1110 0100 > 0000.0111 0100 0100 (0.744) ; 0.0001 111x ;correct for out of bounds, take 1 from output 0000.0111 0100 0100 > 0000.1110 1000 1000 (0.E88) ; 0.0001 111x ;out of bounds detected 0000.1110 1000 1000 > 0000.0100 1000 1000 (0.488) ; 0.0001 1111 ;out of bounds corrected, take 1 from output Test Case 0.5 (0000.0101) 0000.0101 > 0000.1010 ; 0.x ;out of bounds detected 0000.1010 > 0000.0000 ; 0.1 ;corrected for out of bounds, take 1 from output