Computer systems and cloud computing books P39 practice 2.13

Exercise 2.13 
the late 1970s to the late 1980s, DigitalEquipment the VAX computer is a very popular model. It does not Boolean operators AND and OR commands, there are only BIS (bit set) and BIC (bit clear) both instructions. Two kinds of input data word is a command and a mask word x m. They generate a result z. z m is the bit mask according to the changes of position x obtained. Use bis command. For each possible position of 1 m on the position corresponding to z 1. Use bic instructions. M for each possible position of the 1, z is set to the position corresponding to 0. In order to clarify the relationship between bis and bic operation with the C language bit-level operations, if we have two functions bis and bic to achieve bit set and bit clear operations. Just want to use these two functions without using the C language regardless of what other operations to achieve Bitwise | and ^ operations, namely OR and XOR. bis equivalent to or, bic (x, m) is equivalent to x & ~ m. x ^ y = (x & ~ y) | (~ x & y) in the ratio shown below: / * Define two arithmetic functions * / int BIS (INTx, int m); intbic (int X, int m); / * OR implementation * / intbool_or (int X, int Y) { int Result = _______; return Result; } / * XOR implemented * / int bool_xor (int X, int Y) { int Result = ______; return Result; }

understanding of the bis
eg bis ([1001], [ 1101]) = [1101];
the mask for a m bit, whether x is 0 or 1, which are a set;
equivalent to ORing

of understanding bic
EG ( [10011001], [11101000]) = [00010001];
the mask for a m bit, whether x is 0 or 1, which are set to zero;
corresponds to the first mask is inverted so that the original 1 bit becomes 0 and then taken to the x-

BIS (0,0) = 0; BIS (0,1) =. 1; BIS (1,0) =. 1 ; BIS (1,1) =. 1;
BIC (0, 0) = 0; BIC (0,1) = 0; BIC (1,0) =. 1 ; BIC (1,1) = 0;

XOR operation
! x ^ y = (x & ~ y) (y & ~ x)
x ^ y = bis (bic ( x, y), bic (y, x))

Guess you like

Origin www.cnblogs.com/wwqdata/p/11505305.html