Skip to content

Instantly share code, notes, and snippets.

@jeongukjae
Created March 28, 2017 11:47
Show Gist options
  • Save jeongukjae/c40f153b7915b86416847e93ecca172a to your computer and use it in GitHub Desktop.
Save jeongukjae/c40f153b7915b86416847e93ecca172a to your computer and use it in GitHub Desktop.
Homework for Operating System Class
#include <stdio.h>
int subtraction(int num1, int num2) {
int num2_inverted = ~num2; // invert num2 variable
int twos_complement_of_num2 = num2_inverted + 1; // create variable of which
// value is twos complement of num2
return twos_complement_of_num2 + num1; // add twos complement of num2 and num1
}
int main() {
printf("%d", subtraction(10, 5)); // print 10 - 5
return 0;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment