Browse Source

Finish negate and isAsciiDigit

main
邓博昊 1 year ago
parent
commit
ab35332d55
2 changed files with 12 additions and 2 deletions
  1. +8
    -2
      LAB1/bits.c
  2. +4
    -0
      README.md

+ 8
- 2
LAB1/bits.c View File

@ -225,7 +225,7 @@ int allOddBits(int x) {
* Rating: 2 * Rating: 2
*/ */
int negate(int x) { int negate(int x) {
return 2;
return ~x+1;
} }
//3 //3
/* /*
@ -238,7 +238,13 @@ int negate(int x) {
* Rating: 3 * Rating: 3
*/ */
int isAsciiDigit(int x) { int isAsciiDigit(int x) {
return 2;
//
//
int downstream = ~0x30+1;
int upstream = ~0x39;
int leftside = !((downstream+x)>>31); //0x300
int rightside = !!((upstream+x)>>31); //0x391
return leftside&rightside;
} }
/* /*
* conditional - same as x ? y : z * conditional - same as x ? y : z

+ 4
- 0
README.md View File

@ -13,3 +13,7 @@ A CSAPP LAB
1. Finish isTmax 1. Finish isTmax
2. Finish allOddBits 2. Finish allOddBits
3. Finish negate
4. Finish isAsciiDigit

Loading…
Cancel
Save