c言語で「8ビット乗算器を用いて16ビット乗算器の作成」という課題が与えられました
#include <stdio.h>
int main()
{
unsigned long a, b, c, d;
unsigned long a1, a0, b1, b0, c11, c10, c01, c00;
for (b = 0x00; b < 0x100; ++b) { b1 = (0x0F0 & b) >> 4; b0 = 0x0F & b; for (a = 0x00; a < 0x100; ++a) { d = a * b; a1 = (0x0F0 & a) >> 4; a0 = 0x0F & a; c00 = a0 * b0; c01 = a0 * b1; c10 = a1 * b0; c11 = a1 * b1; c = (c11 << 8) + (c10 << 4) + (c01 << 4) + c00; if (c != d) printf("%lu * %lu = %lu != %lu¥n", a, b, d, c); } }
return 0;
}
こんな感じ?
回答2件
あなたの回答
tips
プレビュー