Created
March 28, 2017 11:48
-
-
Save jeongukjae/c6745d363edfc58a40b120b147797b18 to your computer and use it in GitHub Desktop.
Homework of Operating System Class
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include <stdio.h> | |
int division(int num1, int num2); | |
int main() { | |
printf("%d", division(300, 5)); | |
return 0; | |
} | |
int division(int num1, int num2) { | |
// Quotient = result | |
int result = 0; | |
// loop 32. (Integer is 32bit) | |
for(int i = 31;i >= 0;i--) { | |
result = result << 1; | |
int num1_current = num1 >> i; | |
if(num1_current >= num2) { | |
num1 = num1 - (num2 << i); | |
result++; | |
} | |
} | |
return result; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment