-
Notifications
You must be signed in to change notification settings - Fork 0
/
bit_tests1.c
50 lines (40 loc) · 1.42 KB
/
bit_tests1.c
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
#include <stdio.h>
#include <memory.h>
#define CHAR_BIT 8
uint32_t rotl32 (uint32_t value, unsigned int count);
uint32_t rotr32 (uint32_t value, unsigned int count);
uint32_t set_bit (uint32_t number, uint32_t x, uint32_t n);
void main(void)
{
SignalStructure signal = {0, 1};
uint32_t mask = 0xFFFE;
uint32_t mask1 = 0xFFFF;
uint32_t position = 15;
uint32_t x = 0;
int value = 1;
printf("mask = %u\n", mask);
mask = rotl32(mask, 2);
printf("mask = %u\n", mask);
printf("mask1 = %u\n", mask1);
// mask1 = set_bit(mask1, x, position);
// mask1 |= 0 << position;
mask1 &= ~(1 << position);
printf("mask1 = %u\n", mask1);
/*printf("the value is: %d\n", (Register & signal.SignalAddressOffset)>>signal.SignalAddressOffset);
printf("the value is: %d\n", (Register & signal.SignalAddressOffset)>>signal.SignalAddressOffset);*/
}
uint32_t rotl32 (uint32_t value, unsigned int count) {
const unsigned int mask = CHAR_BIT * sizeof(value) - 1;
count &= mask;
return (value << count) | (value >> (-count & mask));
}
uint32_t rotr32 (uint32_t value, unsigned int count) {
const unsigned int mask = CHAR_BIT * sizeof(value) - 1;
count &= mask;
return (value >> count) | (value << (-count & mask));
}
uint32_t set_bit (uint32_t number, uint32_t x, uint32_t n)
{
number ^= (-x ^ number) & (1UL << n);
return number;
}