I am trying to type the C programming code to run the computation by four arithmetic operators, and them print out the result as a 16 bit binary number.
However, I am stuck on writing the legal function divide() that our class are requiring us to handin:
This code actually worked and returned the variable as "result" back to the main function. Thus, my main function will take the two shorts (variables) and print the output as:Code:short divide(short num1, short num2) { short i, result = 0; fum2 = num2 << 8; for(i = 0x100; i > 0; i = i >> 1){ if(num1 >= num2){ result = result + 1; num1 = num1 – num2; } num2 = num2 >> 1; } return result; }
254 / 16 = 0000000000001111
or
25 / 25 = 0000000000000001
However, there is a TRICKY part:
My instructor only allow us to use the operators such as: &&, ||, &, |, <<, >>, +, -, ==, !=, and = on the function divide()
In this case, my code would be illegal since I use operators as >= and >. I can't think about using the above allowed operators to complete this function, so I need help. Can anyone enlightened me how I should wirte this code satisfying the above condition?