-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathlib.c
More file actions
98 lines (77 loc) · 2.56 KB
/
lib.c
File metadata and controls
98 lines (77 loc) · 2.56 KB
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
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
#include "lib.h"
// еденицы по маске
uint8_t setOne8(uint8_t number, uint8_t mask){
return number | mask;
}
uint16_t setOne16(uint16_t number, uint16_t mask){
return number | mask;
}
uint32_t setOne32(uint32_t number, uint32_t mask){
return number | mask;
}
// нули по маске
uint8_t setNull8(uint8_t number, uint8_t mask){
return number & mask;
}
uint16_t setNull16(uint16_t number, uint16_t mask){
return number & mask;
}
uint32_t setNull32(uint32_t number, uint32_t mask){
return number & mask;
}
// инверсия по маске
uint8_t setInv8(uint8_t number, uint8_t mask){
return number ^ mask;
}
uint16_t setInv16(uint16_t number, uint16_t mask){
return number ^ mask;
}
uint32_t setInv32(uint32_t number, uint32_t mask){
return number ^ mask;
}
// Логический сдвиг влево
uint8_t shiftLeft8(uint8_t number, uint8_t shift_count) {
return number << shift_count;
}
uint16_t shiftLeft16(uint16_t number, uint8_t shift_count) {
return number << shift_count;
}
uint32_t shiftLeft32(uint32_t number, uint8_t shift_count) {
return number << shift_count;
}
// Логический сдвиг вправо
uint8_t shiftRight8(uint8_t number, uint8_t shift_count) {
return number >> shift_count;
}
uint16_t shiftRight16(uint16_t number, uint8_t shift_count) {
return number >> shift_count;
}
uint32_t shiftRight32(uint32_t number, uint8_t shift_count) {
return number >> shift_count;
}
// Циклический сдвиг влево
uint8_t rotateLeft8(uint8_t number, uint8_t shift_count) {
shift_count %= 8; // Нормализуем сдвиг (0-7)
return (number << shift_count) | (number >> (8 - shift_count));
}
uint16_t rotateLeft16(uint16_t number, uint8_t shift_count) {
shift_count %= 16;
return (number << shift_count) | (number >> (16 - shift_count));
}
uint32_t rotateLeft32(uint32_t number, uint8_t shift_count) {
shift_count %= 32;
return (number << shift_count) | (number >> (32 - shift_count));
}
// Циклический сдвиг вправо
uint8_t rotateRight8(uint8_t number, uint8_t shift_count) {
shift_count %= 8; // Нормализуем сдвиг (0-7)
return (number >> shift_count) | (number << (8 - shift_count));
}
uint16_t rotateRight16(uint16_t number, uint8_t shift_count) {
shift_count %= 16;
return (number >> shift_count) | (number << (16 - shift_count));
}
uint32_t rotateRight32(uint32_t number, uint8_t shift_count) {
shift_count %= 32;
return (number >> shift_count) | (number << (32 - shift_count));
}