Created
March 28, 2017 11:47
-
-
Save jeongukjae/c40f153b7915b86416847e93ecca172a to your computer and use it in GitHub Desktop.
Homework for 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 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