//16進表現 2バイト割り算 unsigned変数の利用
#include <stdio.h>
int main()
{
unsigned short int x00,x10;
unsigned short int x0,x1,x2; //x0÷x1=x2 あまり x0を作る
unsigned short int x3;
printf("x00(Hex) x01(Hex) = ");
scanf("%hx %hx",&x00,&x10);
x0=x00;
x1=x10;
x2=0;
x3=1;
while (x1<x0 && (x1&0x8000)!=0x8000) {
x1<<=1;
x3<<=1;
printf("in while x0,x1,x2,x3= %04hx, %04hx, %04hx, %04hx\n",x0,x1,x2,x3);
}
printf("x0,x1,x2,x3= %04hx, %04hx, %04hx, %04hx\n", x0,x1,x2,x3);
while (x3!=0) {
if(x1<=x0) {
x0-=x1;
x2+=x3;
}
x1>>=1;
x3>>=1;
}
printf("x00,x10,x2,x0= %04hx, %04hx, %04hx, %04hx\n", x00,x10,x2,x0);
printf("x00,x10,x2,x0=%6d,%6d,%6d,%6d\n", x00,x10,x2,x0);
return 0;
}
/*
x00(Hex) x01(Hex) = 3 2
in while x0,x1,x2,x3= 0003, 0004, 0000, 0002
x0,x1,x2,x3= 0003, 0004, 0000, 0002
x00,x10,x2,x0= 0003, 0002, 0001, 0001
x00,x10,x2,x0= 3, 2, 1, 1
x00(Hex) x01(Hex) = 1000 33
in while x0,x1,x2,x3= 1000, 0066, 0000, 0002
in while x0,x1,x2,x3= 1000, 00cc, 0000, 0004
in while x0,x1,x2,x3= 1000, 0198, 0000, 0008
in while x0,x1,x2,x3= 1000, 0330, 0000, 0010
in while x0,x1,x2,x3= 1000, 0660, 0000, 0020
in while x0,x1,x2,x3= 1000, 0cc0, 0000, 0040
in while x0,x1,x2,x3= 1000, 1980, 0000, 0080
x0,x1,x2,x3= 1000, 1980, 0000, 0080
x00,x10,x2,x0= 1000, 0033, 0050, 0010
x00,x10,x2,x0= 4096, 51, 80, 16
x00(Hex) x01(Hex) = aaaa bb
in while x0,x1,x2,x3= aaaa, 0176, 0000, 0002
in while x0,x1,x2,x3= aaaa, 02ec, 0000, 0004
in while x0,x1,x2,x3= aaaa, 05d8, 0000, 0008
in while x0,x1,x2,x3= aaaa, 0bb0, 0000, 0010
in while x0,x1,x2,x3= aaaa, 1760, 0000, 0020
in while x0,x1,x2,x3= aaaa, 2ec0, 0000, 0040
in while x0,x1,x2,x3= aaaa, 5d80, 0000, 0080
in while x0,x1,x2,x3= aaaa, bb00, 0000, 0100
x0,x1,x2,x3= aaaa, bb00, 0000, 0100
x00,x10,x2,x0= aaaa, 00bb, 00e9, 0077
x00,x10,x2,x0= 43690, 187, 233, 119
x00(Hex) x01(Hex) = bbbb aa
in while x0,x1,x2,x3= bbbb, 0154, 0000, 0002
in while x0,x1,x2,x3= bbbb, 02a8, 0000, 0004
in while x0,x1,x2,x3= bbbb, 0550, 0000, 0008
in while x0,x1,x2,x3= bbbb, 0aa0, 0000, 0010
in while x0,x1,x2,x3= bbbb, 1540, 0000, 0020
in while x0,x1,x2,x3= bbbb, 2a80, 0000, 0040
in while x0,x1,x2,x3= bbbb, 5500, 0000, 0080
in while x0,x1,x2,x3= bbbb, aa00, 0000, 0100
x0,x1,x2,x3= bbbb, aa00, 0000, 0100
x00,x10,x2,x0= bbbb, 00aa, 011a, 0077
x00,x10,x2,x0= 48059, 170, 282, 119
x00(Hex) x01(Hex) = 1007 10
in while x0,x1,x2,x3= 1007, 0020, 0000, 0002
in while x0,x1,x2,x3= 1007, 0040, 0000, 0004
in while x0,x1,x2,x3= 1007, 0080, 0000, 0008
in while x0,x1,x2,x3= 1007, 0100, 0000, 0010
in while x0,x1,x2,x3= 1007, 0200, 0000, 0020
in while x0,x1,x2,x3= 1007, 0400, 0000, 0040
in while x0,x1,x2,x3= 1007, 0800, 0000, 0080
in while x0,x1,x2,x3= 1007, 1000, 0000, 0100
in while x0,x1,x2,x3= 1007, 2000, 0000, 0200
x0,x1,x2,x3= 1007, 2000, 0000, 0200
x00,x10,x2,x0= 1007, 0010, 0100, 0007
x00,x10,x2,x0= 4103, 16, 256, 7
*/
/*
//事前調査
//short int は何バイトかチェック
int main()
{
printf("%d\n",sizeof(int));
printf("%d\n",sizeof(short int));
return 0;
}
//unsigned short int で最上位ビットが1の場合でも
//大小判断は出来るかチェック
int main()
{
unsigned short int a=0xaaaa;
unsigned short int b=0xbbbb;
if (a<b) printf("a<b\n");
if (b<a) printf("b<a\n");
return 0;
}
*/