Browse Source

Finish howManyBits

main
邓博昊 8 months ago
parent
commit
94acc0aeea
2 changed files with 29 additions and 2 deletions
  1. +25
    -1
      LAB1/bits.c
  2. +4
    -1
      README.md

+ 25
- 1
LAB1/bits.c View File

@ -296,7 +296,31 @@ int logicalNeg(int x) {
* Rating: 4
*/
int howManyBits(int x) {
return 0;
x = ((~(x>>31))&x)|(x>>31&~x);//
//
int tf = !!(x>>16); //1601
int b16 = tf << 4; //16b16为16016
x = x>>b16; //b16位16161616
tf = !!(x>>8); //8,
int b8 = tf << 3;//8b8为808
x = x>>b8;
tf = !!(x>>4);
int b4 = tf << 2 ; //84,4b4为404
x = x>>b4;
tf = !!(x>>2);
int b2 = tf << 1; //42,2b2为202
x = x>>b2;
tf = !!(x>>1); //211b1为101
int b1 = tf << 0;
x = x>>b1;
int b0 = x;//,1,0
return b0+b1+b2+b4+b8+b16+1; //+11
}
//float
/*

+ 4
- 1
README.md View File

@ -22,4 +22,7 @@ A CSAPP LAB
6. Finish logicalNeg
7. Update Makefile
7. Update Makefile
### 2023/10/9 Update:
1. Finish howManyBits

Loading…
Cancel
Save