Skip to content

Instantly share code, notes, and snippets.

@nkoneko
Created June 4, 2014 12:26
Show Gist options
  • Save nkoneko/2bbdabc29fac6b7ee194 to your computer and use it in GitHub Desktop.
Save nkoneko/2bbdabc29fac6b7ee194 to your computer and use it in GitHub Desktop.
#include <stdio.h>
#include <stdlib.h>
#include <limits.h>
unsigned short calc(unsigned short u)
{
return u ^ (u >> 1);
}
void print_bits(unsigned short u, unsigned short v)
{
int i, j;
i = sizeof(v) * CHAR_BIT;
printf("%u\t", u);
for (j = i; j > 0; --j)
{
printf("%u", (v >> (j - 1)) & 0x01);
}
printf("\n");
}
int main(int argc, char **argv)
{
unsigned short u, v;
if (argc != 2) exit(1);
u = atoi(argv[1]);
v = calc(u);
print_bits(u, v);
return 0;
}
#!/bin/bash
begin=${1}
end=${2}
i=${begin}
while [ ${i} -le ${end} ]
do
echo ${1}
i=[${i} + 1]
done
ogawa@debian:~/tmp$ gcc -o encode encode.c
ogawa@debian:~/tmp$ chmod +x range.sh
ogawa@debian:~/tmp$ ./range.sh 0 35 | xargs -i ./encode {}
0 0000000000000000
1 0000000000000001
2 0000000000000011
3 0000000000000010
4 0000000000000110
5 0000000000000111
6 0000000000000101
7 0000000000000100
8 0000000000001100
...
23 0000000000011100
24 0000000000010100
...
35 0000000000110010
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment