Browse Source

Finish isLessOrEqual

main
邓博昊 1 year ago
parent
commit
6e57a492d8
2 changed files with 9 additions and 2 deletions
  1. +7
    -2
      LAB1/bits.c
  2. +2
    -0
      README.md

+ 7
- 2
LAB1/bits.c View File

@ -254,7 +254,9 @@ int isAsciiDigit(int x) {
* Rating: 3
*/
int conditional(int x, int y, int z) {
return 2;
x = !!(x);
x = ~x+1;
return (x&y)|(~x&z);
}
/*
* isLessOrEqual - if x <= y then return 1, else return 0
@ -264,7 +266,10 @@ int conditional(int x, int y, int z) {
* Rating: 3
*/
int isLessOrEqual(int x, int y) {
return 2;
int tmp = ~y+1;
tmp = tmp+x-1;
tmp = tmp >> 31;//y大0y小等于1
return !!tmp;
}
//4
/*

+ 2
- 0
README.md View File

@ -17,3 +17,5 @@ A CSAPP LAB
3. Finish negate
4. Finish isAsciiDigit
5. Finish isLessOrEqual

Loading…
Cancel
Save