-
Notifications
You must be signed in to change notification settings - Fork 0
/
bitmask_helpers.c
48 lines (43 loc) · 1.39 KB
/
bitmask_helpers.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
/* ************************************************************************** */
/* */
/* :::::::: */
/* bitmask_helpers.c :+: :+: */
/* +:+ */
/* By: cschuijt <[email protected]> +#+ */
/* +#+ */
/* Created: 2022/11/22 14:02:42 by cschuijt #+# #+# */
/* Updated: 2022/11/22 14:02:42 by cschuijt ######## odam.nl */
/* */
/* ************************************************************************** */
#include "so_long.h"
int check_against_bitmask(uint8_t input, char *mask, int c)
{
size_t i;
uint8_t orig;
uint8_t match;
i = 0;
match = 0;
orig = input;
while (mask[i])
{
if (mask[i] == '1')
match |= 1 << i;
if (mask[i] == '*')
input &= ~(1 << i);
i++;
}
if (input == match)
return (1);
c--;
if (c > 0)
return (check_against_bitmask(cyclical_shift_two(orig), mask, c));
return (0);
}
uint8_t cyclical_shift_two(uint8_t in)
{
uint8_t swap;
swap = (in >> 6);
in <<= 2;
in += swap;
return (in);
}