Question: Can you please convert this code from C language to JAVA language? #include #include void division(char x, char y) { register char A, M, Q;

Can you please convert this code from C language to JAVA language?

#include #include

void division(char x, char y) { register char A, M, Q;

unsigned char t, s, r;

int i;

Q = x; M = y; A = 0;

//display initial values in A, Q and M printf("Initially: A = %d Q = %d M = %d ", A, Q, M);

Q = abs(x); M = abs(y);

r = sizeof(char)*8;

t = 1 << (r-1);

for(i=0; i < r; i++) { //shift left AQ A = A <<1; s = Q & t; s = s >> (r-1); Q = Q << 1; A = A | s;

//A = A -M A = A - M;

//MSB of A s = A & t; s = s >> (r-1);

//check MSB if(s==0) //Q[0] = 1 Q = Q | 1; else { //Q[0] = 0 Q = Q | 0; //restore A A = A + M; } } if(x<0) A = ~A + 1;

if(x<0 && y>0 || x>0 && y<0) Q = ~Q + 1;

//display Quotient and Remainder printf("Quotient = %d\t", Q); printf("Remainder = %d ", A);

printf("%dR%d ", Q, A);

}

int main() { int a, b;

printf("Enter dividend and divisor: "); scanf("%d%d", &a, &b);

division(a, b); }

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!