Advertisement
B1KMusic

Two's complement test

Feb 7th, 2015
374
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 0.21 KB | None | 0 0
  1. #include <stdio.h>
  2.  
  3. int tc(int n){
  4.   // Two's complement function, returns (NOT n) + 1
  5.   return ~n + 1;
  6. }
  7.  
  8. int main(){
  9.   int i = 5;
  10.   printf("2c(%i) = %i\n", i, tc(i)); // prints "2c(5) = -5"
  11.   return 0;
  12. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement