Originally Posted by

**itsme86**
Really? Are you serious? Did you even read the requirements?

The point is not to use "-" and "--", becouse it (the code) should look like a simulation of the subtraction in the processor. So bitwise operators sholud be used. I have created funkcions that can substract **2 binary numbers **, like the processor does. The problem I need to figure out is how to implement that operation on two numbers whos base is larger than 16, becouse than i have to implement the substraction of two numbers on each digit( if the base is 16 it is easy becouse each digit in those numbers can not exceed F,(15)). When the Base is i dont know 145, the largest digit that can be found in a number with a base 145 is 144!!! It can not be represented by one character. I will have to extract each number, and represent it as sequence of bits, where every byte symbolizes a digit. here are the functions i`ve got:

Code:

/*the function takes a bit from data x , from position number i , and puts it in to the lowest bit in data on which points b.*/
void get_bit(unsigned x, int i, unsigned * b)
{
*b = (x >> i) & 1;
}
/*I will not explain each function , you will understand it.*/
void set_bit(unsigned * x, int i, unsigned b)
{
*x = (b << i) | (*x & ~(1 << i));
}
void half_substract(unsigned x, unsigned y, unsigned * S, unsigned * C)
{
*S = x ^ y;
*C = (x ^ 1) & y;
}
void full_substract(unsigned x, unsigned y, unsigned pc,
unsigned * S, unsigned * C)
{
unsigned S1, C1, C2;
half_substract(x, y, &S1, &C1);
half_substract(S1, pc, S, &C2);
*C = C1 | C2;
}
void sub_unsigned(unsigned x, unsigned y, unsigned * S, unsigned * C)
{
int i;
unsigned bx, by;
unsigned bs, bc, pc = 0;
for(i = 0; i < 32; i++)
{
get_bit(x, i, &bx);
get_bit(y, i, &by);
full_substract(bx, by, pc, &bs, &bc);
set_bit(S, i, bs);
pc = bc;
}
*C = pc;
}

Every help and every advice can come good.