2-6

xiaoxiao2021-03-06  50

/ *

Write a function setBits (X, P, N, Y), which returns the result value after the following operation:

Set the N binary bits starting from the first P- in X to the value of the rightmost N bit in Y, the remaining points of X remain unchanged.

* /

Int sets (int X, int p, int N, int y)

{

/ *

X = 11011001, P = 3, n = 3, y = 00110111 ---> x = 11 111 001

* /

Return (~ (~ 0 << n) << p) | ((~ (~ 0 << n) & y) << p);

}

转载请注明原文地址:https://www.9cbs.com/read-117396.html

New Post(0)