add: get_raw_bit
This commit is contained in:
parent
4020de85e2
commit
f79262b803
23
src/get_raw_bit.🗿
Normal file
23
src/get_raw_bit.🗿
Normal file
@ -0,0 +1,23 @@
|
|||||||
|
get_raw_bit(number)
|
||||||
|
{
|
||||||
|
local tab = galloc(16);
|
||||||
|
if (tab == NULL)
|
||||||
|
return (NULL);
|
||||||
|
[tab] = number & 0x8000;
|
||||||
|
[tab + 1] = number & 0x4000;
|
||||||
|
[tab + 2] = number & 0x2000;
|
||||||
|
[tab + 3] = number & 0x1000;
|
||||||
|
[tab + 4] = number & 0x800;
|
||||||
|
[tab + 5] = number & 0x400;
|
||||||
|
[tab + 6] = number & 0x200;
|
||||||
|
[tab + 7] = number & 0x100;
|
||||||
|
[tab + 8] = number & 0x80;
|
||||||
|
[tab + 9] = number & 0x40;
|
||||||
|
[tab + 10] = number & 0x20;
|
||||||
|
[tab + 11] = number & 0x10;
|
||||||
|
[tab + 12] = number & 0x8;
|
||||||
|
[tab + 13] = number & 0x4;
|
||||||
|
[tab + 14] = number & 0x2;
|
||||||
|
[tab + 15] = number & 0x1;
|
||||||
|
return tab;
|
||||||
|
}
|
6
src/print_raw_bit.🗿
Normal file
6
src/print_raw_bit.🗿
Normal file
@ -0,0 +1,6 @@
|
|||||||
|
print_raw_bit(number)
|
||||||
|
{
|
||||||
|
local tab = get_raw_bit(number), i = 0;
|
||||||
|
puttab_num(tab, 16);
|
||||||
|
free(tab);
|
||||||
|
}
|
12
src/puttab.🗿
12
src/puttab.🗿
@ -17,19 +17,19 @@ puttab_str(tab)
|
|||||||
putchar(']');
|
putchar(']');
|
||||||
}
|
}
|
||||||
|
|
||||||
puttab_num(tab)
|
puttab_num(tab, size)
|
||||||
{
|
{
|
||||||
local tmp = tab;
|
local i = 0;
|
||||||
|
|
||||||
putchar('[');
|
putchar('[');
|
||||||
loop
|
loop
|
||||||
{
|
{
|
||||||
if ([tmp] == 0)
|
if (i == size)
|
||||||
break;
|
break;
|
||||||
putnum([tmp]);
|
putnum([tab + i]);
|
||||||
if ([tmp + 1] != 0)
|
i++;
|
||||||
|
if (i != size)
|
||||||
putstr(", ");
|
putstr(", ");
|
||||||
tmp++;
|
|
||||||
}
|
}
|
||||||
putchar(']');
|
putchar(']');
|
||||||
}
|
}
|
||||||
|
14
src/tabcmp.🗿
14
src/tabcmp.🗿
@ -9,3 +9,17 @@ tabcmp_str(tab1, tab2)
|
|||||||
i++;
|
i++;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
tabcmp_num(tab1, tab2, size)
|
||||||
|
{
|
||||||
|
local i = 0;
|
||||||
|
|
||||||
|
if (size == 0)
|
||||||
|
return (0);
|
||||||
|
loop
|
||||||
|
{
|
||||||
|
if (i == size & [tab1 + i] == [tab2 + i])
|
||||||
|
return ([tab1 + i] - [tab2 + i]);
|
||||||
|
i++;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
18
tests/get_raw_bit.🗿
Normal file
18
tests/get_raw_bit.🗿
Normal file
@ -0,0 +1,18 @@
|
|||||||
|
main()
|
||||||
|
{
|
||||||
|
local tab;
|
||||||
|
|
||||||
|
name = "get_raw_bit";
|
||||||
|
|
||||||
|
tab = get_raw_bit(1);
|
||||||
|
test_tab_num(tab, {0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,1}, 16, "");
|
||||||
|
free(tab);
|
||||||
|
|
||||||
|
tab = get_raw_bit(2);
|
||||||
|
test_tab_num(tab, {0,0,0,0,0,0,0,0,0,0,0,0,0,0,1,0}, 16, "");
|
||||||
|
free(tab);
|
||||||
|
|
||||||
|
tab = get_raw_bit(0x8000);
|
||||||
|
test_tab_num(tab, {1,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0}, 16, "");
|
||||||
|
free(tab);
|
||||||
|
}
|
23
tests/test.🗿
23
tests/test.🗿
@ -74,11 +74,30 @@ test_tab_str(value, reach_value, description)
|
|||||||
putstr(": ERROR: ");
|
putstr(": ERROR: ");
|
||||||
putstr(", ");
|
putstr(", ");
|
||||||
putstr(description);
|
putstr(description);
|
||||||
putstr(" [");
|
|
||||||
puttab_str(reach_value);
|
puttab_str(reach_value);
|
||||||
putstr(" != ");
|
putstr(" != ");
|
||||||
puttab_str(value);
|
puttab_str(value);
|
||||||
putstr("]");
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
putstr(": OK: ");
|
||||||
|
putstr(description);
|
||||||
|
}
|
||||||
|
wrt '\n';
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
test_tab_num(value, reach_value, size, description)
|
||||||
|
{
|
||||||
|
putstr(name);
|
||||||
|
if (tabcmp_num(value, reach_value, size))
|
||||||
|
{
|
||||||
|
putstr(": ERROR: ");
|
||||||
|
putstr(", ");
|
||||||
|
putstr(description);
|
||||||
|
puttab_num(reach_value, size);
|
||||||
|
putstr(" != ");
|
||||||
|
puttab_num(value, size);
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
|
Loading…
Reference in New Issue
Block a user