9511_workbook

solved exercises from algorithms & programming I (9511) prof. Cardozo
Index Commits Files Refs README
commit d59227bc2cb4ab4e047ff20f918de68a658687a9
parent 617b3938839aee829707aceba484770022201b46
Author: klewer-martin <martin.cachari@gmail.com>
Date:   Fri, 12 Feb 2021 16:24:18 -0300

Exercise guide update: added ex01.c;

Diffstat:
Aguia07/ex01.c | 55+++++++++++++++++++++++++++++++++++++++++++++++++++++++
1 file changed, 55 insertions(+), 0 deletions(-)
diff --git a/guia07/ex01.c b/guia07/ex01.c
@@ -0,0 +1,55 @@
+#include <stdio.h>
+
+
+typedef enum {
+    OK,
+    ERROR
+} status_t;
+
+status_t print_byte(unsigned char *byte);
+
+int main (void)
+{
+    unsigned char a, b, res;
+
+    a = 0b11001010;
+    b = 0b10100101;
+
+    printf("a = ");
+    print_byte(&a);
+
+    printf("b = ");
+    print_byte(&b);
+    putchar('\n');
+        
+    printf("& = ");
+    res = (a & b);
+    print_byte(&res);
+
+    printf("| = ");
+    res = (a | b);
+    print_byte(&res);
+
+
+    printf("^ = ");
+    res = (a ^ b);
+    print_byte(&res);
+    return OK;
+}
+
+status_t print_byte(unsigned char *byte) 
+{
+    if(byte == NULL) return ERROR;
+
+    unsigned char aux = 0x01;
+    for(int i = ((sizeof(*byte) * 8) - 1); i >= 0; i--)
+        putchar(((*byte) & (aux << i)) ? '1' : '0');
+
+    putchar('\n');
+    return OK;
+}
+
+
+
+//    for(size_t i = 0; i < (sizeof(*byte) * 8); i++)
+//        putchar(((*byte) & (aux << i)) ? '1' : '0');