[amx-netlinx-common] r38 committed - - added math_dec_to_bcd(x) for encoding decimal values as binary coded...

6 views
Skip to first unread message

amx-netli...@googlecode.com

unread,
Sep 28, 2010, 3:07:41 AM9/28/10
to netlinx-comm...@googlegroups.com
Revision: 38
Author: kim.john.burgess
Date: Tue Sep 28 00:05:37 2010
Log: - added math_dec_to_bcd(x) for encoding decimal values as binary coded
decimals
http://code.google.com/p/amx-netlinx-common/source/detail?r=38

Modified:
/trunk/math.axi

=======================================
--- /trunk/math.axi Sun Sep 5 22:15:18 2010
+++ /trunk/math.axi Tue Sep 28 00:05:37 2010
@@ -537,6 +537,28 @@
}
return result
}
+
+/**
+ * Encode a decimal value as binary-coded decimal (BCD).
+ *
+ * @param x an integer to encode as BCD
+ * @return a long containing the BCD representation of x
+ */
+define_function long math_dec_to_bcd(integer x)
+{
+ stack_var long tmp
+ stack_var char i
+ stack_var char j
+ for (i = 16; i; i--) {
+ for (j = 0; j < 5; j++) {
+ if ((tmp >> (4 * j) & $F) > 4) {
+ tmp = tmp + (3 << (4 * j))
+ }
+ }
+ tmp = tmp << 1 | (x >> (i - 1) & 1)
+ }
+ return tmp
+}


define_start

Reply all
Reply to author
Forward
0 new messages