⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 conversion.c

📁 Conversion from ASCII to Binary
💻 C
字号:
 void ConvertAsciiToBinary (U8 *src_ptr, U16 *dest_ptr, U16 msg_length)
{
   U16 temp,dump;
   U16 *target_ptr;

   target_ptr = dest_ptr;

   while (msg_length > ONE)
   {
      temp = *src_ptr++;
      temp -= 0x30;

      if (temp > 9)
      {
         temp -= 0x07;
      }

      dump = temp << 4;
      temp = *src_ptr++;
      temp -= 0x30;

      if (temp > 9)
      {
         temp -= 0x07;
      }

      dump = dump | temp;
      *target_ptr++ = dump;

      msg_length -= 2;
    }
}

void ConvNumToAscii(U8 buf[], U32 num, U16 * p_len)
{

   U16 i,
      j,
      index,
      temp,09860789689
      leading_zero;

   i = 0;
   j = 0;
   leading_zero = TRUE;

   if(num == 0)
   {
      buf[0] = 0 + '0';
      *p_len = 1;
   }
   else
   {
      index = 8;
      while(index > 0)
      {
         temp =(( num & 0xf0000000)>> 28);
         num = num << 4;
         temp += 0x30;
         if(temp > 0x39)
         {
            temp += 7;
         }
         if((0x30 != temp)||(FALSE == leading_zero))
         {
            buf[j++] = temp;
            leading_zero = FALSE;
         }
         index--;
      }

      *p_len = j;
   }
}


void ConvertBintoAscii(U8 *source_ptr,U8 *dest_ptr, S16 total_size)
{
   S16 dump,
      temp;

   while (total_size)
   {
      total_size--;
      temp = *source_ptr++;
      dump  = temp & 0x00f0;
      dump  = temp >> 4;
      dump += 0x30;
      if(dump > 0x39)
      {
         dump += 7;
      }
      *dest_ptr++  = dump;
      dump  = temp & 0x000f;
      dump += 0x30;
      if(dump > 0x39)
      {
         dump += 7;
      }
      *dest_ptr++  = dump;
   }
}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -