Przeglądaj źródła

finish quiz5-6

master
吴冕志 1 rok temu
rodzic
commit
1d1f778fa1
1 zmienionych plików z 9 dodań i 2 usunięć
  1. +9
    -2
      lab2/datalab-handout/bits.c

+ 9
- 2
lab2/datalab-handout/bits.c Wyświetl plik

@ -206,7 +206,9 @@ int allOddBits(int x) {
* Rating: 2
*/
int negate(int x) {
return 2;
int notx = ~x;
int res = notx + 1;// since ~x + x = 1111...111 = -1, ~x + x + 1 = 0
return res;
}
//3
/*
@ -219,7 +221,12 @@ int negate(int x) {
* Rating: 3
*/
int isAsciiDigit(int x) {
return 2;
int neg0x3a = ~(0x3a) + 1;
int neg0x30 = ~(0x30) + 1;
int signofminus0x3a = (x + neg0x3a) >> 31; // should be all 1
int signofminus0x30 = (x + neg0x30) >> 31; // should be all 0
int res = !(signofminus0x30 | (~signofminus0x3a));
return res;
}
/*
* conditional - same as x ? y : z

Ładowanie…
Anuluj
Zapisz