diff --git a/src/get_raw_bit.🗿 b/src/get_raw_bit.🗿 new file mode 100644 index 0000000..dec90e0 --- /dev/null +++ b/src/get_raw_bit.🗿 @@ -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; +} diff --git a/src/print_raw_bit.🗿 b/src/print_raw_bit.🗿 new file mode 100644 index 0000000..99d6cd3 --- /dev/null +++ b/src/print_raw_bit.🗿 @@ -0,0 +1,6 @@ +print_raw_bit(number) +{ + local tab = get_raw_bit(number), i = 0; + puttab_num(tab, 16); + free(tab); +} diff --git a/src/puttab.🗿 b/src/puttab.🗿 index 31ef74d..ad40224 100644 --- a/src/puttab.🗿 +++ b/src/puttab.🗿 @@ -17,19 +17,19 @@ puttab_str(tab) putchar(']'); } -puttab_num(tab) +puttab_num(tab, size) { - local tmp = tab; + local i = 0; putchar('['); loop { - if ([tmp] == 0) + if (i == size) break; - putnum([tmp]); - if ([tmp + 1] != 0) + putnum([tab + i]); + i++; + if (i != size) putstr(", "); - tmp++; } putchar(']'); } diff --git a/src/tabcmp.🗿 b/src/tabcmp.🗿 index 2207b89..2e3c4f1 100644 --- a/src/tabcmp.🗿 +++ b/src/tabcmp.🗿 @@ -9,3 +9,17 @@ tabcmp_str(tab1, tab2) 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++; + } +} diff --git a/tests/get_raw_bit.🗿 b/tests/get_raw_bit.🗿 new file mode 100644 index 0000000..278ab55 --- /dev/null +++ b/tests/get_raw_bit.🗿 @@ -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); +} diff --git a/tests/test.🗿 b/tests/test.🗿 index e598296..72fd10b 100644 --- a/tests/test.🗿 +++ b/tests/test.🗿 @@ -74,11 +74,30 @@ test_tab_str(value, reach_value, description) putstr(": ERROR: "); putstr(", "); putstr(description); - putstr(" ["); puttab_str(reach_value); putstr(" != "); 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 {