Ver a proveniência

finish quiz10

master
吴冕志 há 1 ano
ascendente
cometimento
9cb65531cf
1 ficheiros alterados com 39 adições e 3 eliminações
  1. +39
    -3
      lab2/datalab-handout/bits.c

+ 39
- 3
lab2/datalab-handout/bits.c Ver ficheiro

@ -143,8 +143,8 @@ NOTES:
* Rating: 1
*/
int bitXor(int x, int y) {
int p1 = ~x;
int q1 = ~y;
int p1 = ~x;
int q1 = ~y;
int a1 = x&y;
int b1 = ~a1;
int a2 = p1&q1;
@ -293,7 +293,43 @@ int logicalNeg(int x) {
* Rating: 4
*/
int howManyBits(int x) {
return 0;
int sign = x >> 31;//0x00 if postive, 0xffffffff if negative
int abseminus1 = (sign & (~x)) | ((~sign) & x); // x if x >= 0 , -x - 1 if x < 0
int rs16 = abseminus1 >> 16;
int bits16_flag = (!!(rs16) << 31) >> 31; // 0xfffffff if not 0
int bits16 = 16;
int rs16r = (bits16_flag & rs16) | ((~bits16_flag) & abseminus1); // rs16, if rs16 not 0, abseminus1 if rs16 0
int b16 = bits16_flag & bits16;
int rs8 = rs16r >> 8;
int bits8_flag = (!!(rs8) << 31) >> 31; // 0xfffffff if not 0
int bits8 = 8;
int rs8r = (bits8_flag & rs8) | ((~bits8_flag) & rs16r); // rs8, if rs8 not 0, rs16 if rs8 0
int b8 = bits8_flag & bits8;
int rs4 = rs8r >> 4;
int bits4_flag = (!!(rs4) << 31) >> 31; // 0xfffffff if not 0
int bits4 = 4;
int rs4r = (bits4_flag & rs4) | ((~bits4_flag) & rs8r); // rs4, if rs4 not 0, rs8 if rs4 0
int b4 = bits4_flag & bits4;
int rs2 = rs4r >> 2;
int bits2_flag = (!!(rs2) << 31) >> 31; // 0xfffffff if not 0
int bits2 = 2;
int rs2r = (bits2_flag & rs2) | ((~bits2_flag) & rs4r); // rs2, if rs2 not 0, rs4 if rs2 0
int b2 = bits2_flag & bits2;
int rs1 = rs2r >> 1;
int bits1_flag = (!!(rs1) << 31) >> 31; // 0xfffffff if not 0
int bits1 = 1;
int rs1r = (bits1_flag & rs1) | ((~bits1_flag) & rs2r); // rs1, if rs1 not 0, rs2 if rs1 0
int b1 = bits1_flag & bits1;
int is0orneg1 = (!(x ^ (0))) | (!(x ^((1<<31)>>31)));
int res = ((!is0orneg1 << 31 >> 31) & (b16 + b8 + b4 + b2 + b1 + 2)) | is0orneg1;
return res;
}
//float
/*

Carregando…
Cancelar
Guardar