What is a good software to code in c99? Something like eclipse will be awesome.
1)
1 2 3 4 5
/* Divides and takes the floor of a value exterior to this function by 2^POW.
* Does not use the division function. */
void div(int *y, unsignedint pow) {
*y = y[0] >> pow;
}
can someone explain what's the code doing above and what is ">>"
1 2 3 4 5 6 7 8 9 10 11
/* For each bit position i in [0, sizeof(int)*8) calls hello_world i times
* iff the ith bit of the value X points to is set. */
void HI_HI_HI_HI(int *x) {
int i = 0, j = 0, int_bits = sizeof(int) * 8;
for (i = 0; i < int_bits; i++) {
if ((x[0] >> i) & 1)
for (j = 0; j < i; j++)
hello_world();
}
}
1
to set a bit means transform something to 1, to reset a bit is to transform something to 0, to flip a bit is to switch 0 to 1 and 1 to 0. I would think the correct condition for the if loop is | 1 not & 1.
Set = f = f | 1
reset = f = f & 0
flip = f = f ^ 1
can someone explain what's the code doing above and what is ">>"
In this case the ">>" operator is being used as a "bitwise right shift" operator. Basically you take the number that you fed into 'y' in it's binary form; so for example the number '6' is represented by '110'. If you were to shift it right one time by passing the number '1' as the second argument you would get '011' which is '3' in decimal. Remember that the integers that are shifted out in this way are no longer part of the number, so shifting the original number '6' over two times leaves you with '001' which is the number '1' in decimal.
I would think the correct condition for the if loop is | 1 not & 1.
cringe please fix that. As for the rest of that sentence no. If you used the OR operator here it would always resolve to true since OR only requires either value to be set and the value your testing against is a constant '1'.