Posts

Showing posts from January, 2023

Magic Table (to eliminate pointers)

 #include <stdio.h> #define TABLE_LIMIT 128 #define NULLP -32625 #define L_VAL 0 #define R_VAL 1 #define TYPE 2 int magic_table[3][TABLE_LIMIT]; typedef int pointer_t ; enum Types {     INT,     ADDR     }; int genAddr() {     static int count =0;     int base = 111000;          return base + count++; } int init_magic_table() {     int i;     for(i=0; i< TABLE_LIMIT; i++)     {         magic_table[L_VAL][i] = NULLP;          magic_table[R_VAL][i] = NULLP;     }        } void fill_magic_table(int n) {     int i;     for(i=0; i< n; i++)     {                  magic_table[L_VAL][i] = genAddr();        ...

Bitwise +,-,/*

 long long bitwise_div(long long dividend, long long int divisor) {     long long sign = ((dividend < 0) ^ (divisor < 0)) ? -1 : 1;     dividend = abs(dividend);     divisor = abs(divisor);     long long quotient = 0;     while (dividend >= divisor)     {         dividend -= divisor;         ++quotient;     }     return quotient * sign; } int bitwise_multi(int a, int b) {    int result = 0;    while (b > 0) {       if (b & 1) {          result += a;          }       a = a << 1;       b = b >> 1;    }    return result; } int bitwise_sub(int x, int y) {     while (y != 0)     {         int borrow = (~x) & y;         x = x ^ y;     ...