-
-
-
-
-
-
-
-
-
-
-
-
- #include <stdio.h>
- #include <math.h>
- #include "bsfr.h"
-
- #define BITS 4
-
- int SIZE = 0;
-
- const int use_ansi = 1;
-
- void binary(unsigned int ch, int size)
- {
- unsigned int i;
- if (size)
- {
- for (i = 1 << (size - 1); i > 0; i >>= 1)
- fputc ('0' + !! (ch & i), stdout);
- } else {
- printf ("%02x", ch);
- }
- }
-
-
-
-
- int lca_bin (int a, int b)
- {
- if (a == b)
- return a;
-
- if (b > a)
- a ^= b ^= a ^= b;
-
-
-
-
-
- if (!(b & 1) && a < b + (1 << (bsf (b))))
- return (b);
-
- return a & ~((1 << bsr (a ^ b))-1);
- }
-
- int main(int argc, char **argv)
- {
- int j, i;
-
- if (argc > 1)
- SIZE = BITS;
-
- for (j = 0; j < 1 << BITS; j++)
- {
- for (i = 0; i < 1 << BITS; i++)
- {
- if (!j)
- binary (i, SIZE), printf (" %s",i?"":" ");
- else {
- if (i == 0)
- binary (j, SIZE), printf (" | ");
- else {
- if (use_ansi && i == j) printf("\033[1m");
- binary ( lca_bin(i, j) , SIZE);
- if (use_ansi && i == j) printf("\033[0m");
- printf (" ");
- }
- }
- }
- printf("\n");
- }
-
- return 0;
- }
-
This document should validate, please check by clicking: