#include <stdio.h>
// #include <string.h>
int main( void )
{
// [2] 入力した文字列をASCIIコードに応じた2進数に変換するプログラムを作成せよ。
{
char *s = "abc", c;
while (*s) {
c = *s;
for (int i = 0; i < 8; ++i) {
printf("%c", c
% 2 ? '1' : '0'); c <<= 1;
}
++s;
}
}
// また、2進数から文字列に戻す変換を行うプログラムも作成せよ。
{
char c, *bits = "011000010110001001100011"; // abc
while ( *bits ) {
for (int i = 0; i < 8; ++i) {
c <<= 1;
c |= ( *bits++ == '1' );
}
}
}
return 0;
}
I2luY2x1ZGUgPHN0ZGlvLmg+Ci8vICNpbmNsdWRlIDxzdHJpbmcuaD4KCmludCBtYWluKCB2b2lkICkKewogIC8vIFsyXSDlhaXlipvjgZfjgZ/mloflrZfliJfjgpJBU0NJSeOCs+ODvOODieOBq+W/nOOBmOOBnzLpgLLmlbDjgavlpInmj5vjgZnjgovjg5fjg63jgrDjg6njg6DjgpLkvZzmiJDjgZvjgojjgIIKICB7CiAgICBjaGFyICpzID0gImFiYyIsIGM7CgogICAgd2hpbGUgKCpzKSB7CiAgICAgIGMgPSAqczsKICAgICAgZm9yIChpbnQgaSA9IDA7IGkgPCA4OyArK2kpIHsKICAgICAgICBwcmludGYoIiVjIiwgYyAlIDIgPyAnMScgOiAnMCcpOwogICAgICAgIGMgPDw9IDE7CiAgICAgIH0KICAgICAgKytzOwogICAgfQogICAgcHJpbnRmKCJcbiIpOwogIH0KCiAgLy8g44G+44Gf44CBMumAsuaVsOOBi+OCieaWh+Wtl+WIl+OBq+aIu+OBmeWkieaPm+OCkuihjOOBhuODl+ODreOCsOODqeODoOOCguS9nOaIkOOBm+OCiOOAggogIHsKICAgIGNoYXIgYywgKmJpdHMgPSAiMDExMDAwMDEwMTEwMDAxMDAxMTAwMDExIjsgLy8gYWJjCgogICAgd2hpbGUgKCAqYml0cyApIHsKICAgICAgZm9yIChpbnQgaSA9IDA7IGkgPCA4OyArK2kpIHsKICAgICAgICBjIDw8PSAxOwogICAgICAgIGMgfD0gKCAqYml0cysrID09ICcxJyApOwogICAgICB9CiAgICAgIHByaW50ZigiJWMiLCBjKTsKICAgIH0KICAgIHByaW50ZigiXG4iKTsKICB9CgogIHJldHVybiAwOwp9Cg==