Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <stdio.h>
- int main ()
- {
- // ResetBit
- printf("Result 1: %X\n", ResetBit(0xF, 2));
- printf("Result 2: %X\n", ResetBit(0xA, 0));
- // ResetTwoBits
- printf("Result 3: %X\n", ResetTwoBits(0xFF, 3));
- printf("Result 4: %X\n", ResetTwoBits(0xB7, 3));
- // SetBit
- printf("Result 5: %X\n", SetBit(0xA, 0));
- printf("Result 6: %X\n", SetBit(0xE, 2));
- // SetTwoBitsTo
- printf("Result 7: %X\n", SetTwoBitsTo(0xFF, 3, 1));
- printf("Result 8: %X\n", SetTwoBitsTo(0xAF, 3, 2));
- return 0;
- }
- int ResetBit(int x, int p)
- {
- return x & ~(1 << p);
- }
- int ResetTwoBits(int x, int p)
- {
- return x & ~(1 << p) & ~(1 << p+1);
- return x & ~(3 << p);
- }
- int SetBit(int x, int p)
- {
- return x | (1 << p);
- }
- int SetTwoBitsTo(int x, int p, int n)
- {
- //printf("x je: %X\n", x);
- x = ResetTwoBits(x, p);
- //printf("po resetu je x: %X\n", x);
- if(n % 2 == 1) {
- x = SetBit(x, p);
- }
- if((n/2) % 2 == 1) {
- x = SetBit(x, p+1);
- }
- return x;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement