Skip to content

Instantly share code, notes, and snippets.

@jeongukjae
Created March 28, 2017 11:48
Show Gist options
  • Save jeongukjae/c6745d363edfc58a40b120b147797b18 to your computer and use it in GitHub Desktop.
Save jeongukjae/c6745d363edfc58a40b120b147797b18 to your computer and use it in GitHub Desktop.
Homework of Operating System Class
#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