什进制替换成二八什六进制代码这篇文章很不错喔。励志网站长邮箱admin@xxxx.org.cn

什进制替换成二八什六进制代码

您当前位置:主页 > 宝妈常识 >

文章《什进制替换成二八什六进制代码》正文开始>>

  输入壹个数,转募化成二进制,八进制,什六进制数;

  #include

  void decimal_to_hex(intm)

  {

  int j,i=0;

  int len;

  int a[100];

  while(m!=0)

  {

  if(m%2==0)

  a[i]=0;

  else if(m%2==1)

  a[i]=1;

  i++;

  m=m/2;

  }

  len=i;

  printf("2jin zhi shu wei :");

  for(j=len;j>0;j--)

  printf("%3d",a[j-1]);

  printf("\n");

  }

  void decimal_to_oct(intm)

  {

  int j,i=0;

  int len;

  int a[100];

  int t=0;

  int b[8]={0,1,2,3,4,5,6,7};

  while(m!=0)

  {

  for(i=0;i

  {

  if(m%8==b[i])

  {

  a[t]=b[i];

  t++;

  m=m/8;

  }

  }

  }

  printf("8jin zhi shu wei :");

  for(j=t;j>0;j--)

  {

  printf("%d",a[j-1]);

  }

  printf("\n");

  }

  void decimal_to_binary(m)

  {

  int j,i=0;

  int len;

  int a[100];

  int t=0;

  int g;

  int c[100];

  int l;

  int b[16]={0,1,2,3,4,5,6,7,8,9,10,11,12,13,14,15};

  //charb[16]={'0','1','2','3','4','5','6','7','8','9','a','b','c','d','e','f'};

  while(m!=0)

  {

  for(i=0;i

  {

  if(m%16==b[i])

  {

  a[t]=b[i];

  t++;

  m=m/16;

  }

  }

  }

  for(g=0;g

  {

  if(a[g]>=10&&a[g]

  a[g]=a[g]+87;

  }

  printf("16jin zhi shu wei :");

  for(g=t;g>0;g--)

  {

  if(a[g-1]>=0&&a[g-1]

  {

  printf("%d",a[g-1]);

  }

  else

  {

  printf("%c",a[g-1]);

  }

  }

  }

  int main()

  {

  int i,m;

  printf("shuru dai zhuan huan d shu:");

  scanf("%d",&m);

  printf("xuanze yao zhuan huan cheng de jin zhi shu(0~~2):\n");

  printf("0:zhuan huan cheng 2jin zhi shu.\n");printf("1:zhuan huan cheng 8jin zhi shu.\n");printf("2:zhuan huan cheng 16jin zhi shu.\n");scanf("%d",&i);

  switch(i)

  {

  case 0:

  decimal_to_hex(m);break;

  case 1:

  decimal_to_oct(m);break;

  case 2:

  decimal_to_binary(m);break;

什进制替换成二八什六进制代码的上下篇文章
《什进制替换成二八什六进制代码》相关文章
Copyright @ 2011-2017 Power by DedeCms