C

下記の例に利用する型の宣言

typedef signed   char   int8;
typedef unsigned char   uint8;

typedef signed   short  int16;
typedef unsigned short  uint16;

8進数を16進数に変換

uint16 convertFrom8To16(uint8 dataFirst, uint8 dataSecond) {
    uint16 dataBoth = 0x0000;

    dataBoth = dataFirst;
    dataBoth = dataBoth << 8;
    dataBoth |= dataSecond;
    return dataBoth;
}

16進数を8進数に変換

void convertFrom16To8(uint16 dataAll, uint8 *arrayData) {
    //static uint8 arrayData[2] = { 0x00, 0x00 };

    *(arrayData) = (dataAll >> 8) & 0x00FF;
    arrayData[1] = dataAll & 0x00FF;
    //return arrayData;
}

2進数を16進数に変換

void To_string(uint8 *dest,uint8* src,uint8 length)
{
  uint8* xad;
  uint8 i=0;
  uint8 ch;
  xad=src+length-1;
  for(i=0;i<length;i++,xad--)
  {
   ch=(*xad>>4)&0x0F;  //ウメヤハョチ・
   dest[i<<1]=ch+((ch<10)?'0':'7');
   ch=*xad&0x0F;
   dest[(i<<1)+1]=ch+((ch<10)?'0':'7');
  }
}

一つの16進数数値を文字に変換

unsigned char IntToHexChar(unsigned char c)
{
  if (c > 9)
  return (c + 55);
  else
  return (c + 0x30);
}

16進数を文字列に変換

int IntToHexString(uint8 data[], uint8 dst[], int length)
{
    int i = 0;
    //uint8_t data[5]={0x12,0x34,0x56,0xab,0xef};
    //uint8_t dst[256];
    uint8 str[256];
    
    for(i = 0; i<length;i++)
    {
        str[2*i] = data[i]>>4;
        str[2*i+1] = data[i]&0xf;
    }
    
    for(i = 0; i<length;i++)
    {
        sprintf((char *)&dst[i],"%X/n",str[i]);
    }
    /*
    for(i = 0; i<length;i++)
    {
         printf("%c\n",dst[i]);
    }
    */
    return 0;
}


本当にほしかったのはこういうブログだったんだ

コメント:



(画像の文字列を入力して下さい)

トップ   編集 凍結 差分 添付 複製 名前変更 リロード   新規 一覧 単語検索 最終更新   ヘルプ   最終更新のRSS
Last-modified: 2019/12/02 (月) 12:33:00 (1628d)

PCpዾyǗlgĂ܂}WŔ܂z 萔O~ył񂫁z Yahoo yV NTT-X Store

z[y[W ̃NWbgJ[h COiq ӂ邳Ɣ[ COsیI COze