summaryrefslogtreecommitdiff
path: root/test.c
diff options
context:
space:
mode:
authoralekseiplusplus <alekseijeaves@protonmail.com>2023-03-23 16:43:07 +1100
committeralekseiplusplus <alekseijeaves@protonmail.com>2023-03-23 16:43:07 +1100
commitdae1ec0de59f31b533c225a74019ac77a59c92a1 (patch)
treec331c6620373678ad8fc3452d2d44b1c1a21c05a /test.c
first commit I think
Diffstat (limited to 'test.c')
-rw-r--r--test.c25
1 files changed, 25 insertions, 0 deletions
diff --git a/test.c b/test.c
new file mode 100644
index 0000000..e1898c3
--- /dev/null
+++ b/test.c
@@ -0,0 +1,25 @@
+// BCD
+#include"stdio.h"
+
+int toBCD(int x){
+ if (x < 100){
+ int a = ((x / 10) << 4);
+ int b = (x % 10);
+ return (a + b);
+ }
+ else{
+ fprintf(stderr, "Number greater than 99 passed to toBCD()");
+ }
+}
+
+int fromBCD(int x){
+ int a = ((x >> 4) * 10);
+ int b = (x & 0xF);
+ return (a + b);
+}
+
+int main (){
+ int i = 39;
+ printf("1. %d\n2. %d\n3. %d\n", i, toBCD(i), fromBCD(toBCD(i)));
+ return 0;
+} \ No newline at end of file