精华内容
下载资源
问答
  • <div><p>https://duck.co/ia/view/ascii_to_hex</p>该提问来源于开源项目:duckduckgo/zeroclickinfo-goodies</p></div>
  • AsciiHex互转

    千次阅读 2017-03-27 14:14:14
    AsciiHex互转


    uint8_t AsciiToHex(uint8_t cNum)
    {
        if(cNum>='0'&&cNum<='9')
        {
             cNum -= '0';
        }
        else if(cNum>='A'&&cNum<='F')
        {
             cNum -= 'A';
             cNum += 10;
        }
        else if(cNum>='a'&&cNum<='f')
        {
             cNum -= 'a';
             cNum += 10;
        }
        return cNum;
    }


    uint8_t HexToAsii(int16_t val, uint8_t *pbuf)
    {
    int16_t val_temp=0;
    uint8_t dat_len=0;
    val_temp=val;
    if( val<0 )
    {
    val_temp=~val_temp;
    val_temp+=1;
    pbuf[0]='-';
    dat_len++;
    }
    if( (val_temp/10000) != 0 )
    {
    pbuf[dat_len++]=val_temp/10000+'0';
    pbuf[dat_len++]=(val_temp/1000)%10+'0';
    pbuf[dat_len++]=(val_temp/100)%10+'0';
    pbuf[dat_len++]=(val_temp/10)%10+'0';
    pbuf[dat_len++]=val_temp%10+'0';
    }
    else if( (val_temp/1000)%10 != 0 )
    {
    pbuf[dat_len++]=(val_temp/1000)%10+'0';
    pbuf[dat_len++]=(val_temp/100)%10+'0';
    pbuf[dat_len++]=(val_temp/10)%10+'0';
    pbuf[dat_len++]=val_temp%10+'0';
    }
    else if( (val_temp/100)%10 != 0  )
    {
    pbuf[dat_len++]=(val_temp/100)%10+'0';
    pbuf[dat_len++]=(val_temp/10)%10+'0';
    pbuf[dat_len++]=val_temp%10+'0';
    }
    else if( (val_temp/10)%10 != 0 )
    {
    pbuf[dat_len++]=(val_temp/10)%10+'0';
    pbuf[dat_len++]=val_temp%10+'0';
    }
    else
    {
    pbuf[dat_len++]=val_temp%10+'0';
    }
    return dat_len;
    }


    展开全文
  • ASCIIhex互转工具

    2018-04-18 09:57:25
    ASCIIhex互转工具,hex端填的时候需要加上空格。很方便
  • asciihex

    2020-07-19 14:13:06
    unsigned char ascii2hex(unsigned char ascii) { unsigned char ren = 0; if((ascii >= '0') && (ascii <= '9')) { ren = ascii - '0'; } else if((ascii >= 'A') && (ascii <=...
    unsigned char ascii2hex(unsigned char ascii)
    {
    	unsigned char ren = 0;
    	if((ascii >= '0') && (ascii <= '9'))
    	{
    		ren = ascii - '0';
    	}
    	else if((ascii >= 'A') && (ascii <= 'F'))
    	{
    		ren = ascii - 'A' + 0x0A;
    
    	}
    	else if((ascii >= 'a') && (ascii <= 'f'))
    	{
    		ren = ascii - 'a' + 0x0A;
    	}
    
    	return ren;
    }
    
    展开全文
  • hexToAscii AsciitoHex 网上收集

    千次阅读 2010-01-20 21:56:00
    ////////////////////////////////////////////////////eg1:hexToAscii//////////////////////////////////////////////////#include #include /** To convert 53 to the character S:* char returnVal = hexToS

    //
    //eg1:hexToAscii
    //

    #include <stdio.h>
    #include <stdlib.h>

    /*
    * To convert 53 to the character 'S':
    * char returnVal = hexToString('5', '3');
    */
    char hexToAscii(char first, char second)
    {
     char hex[5], *stop;
     hex[0] = '0';
      hex[1] = 'x';
      hex[2] = first;
      hex[3] = second;
      hex[4] = 0;
      return  strtol(hex, &stop, 16);
    }


    int main(int argc, char* argv[])
    {
     printf("%c/n", hexToAscii('5', '3'));
    }

    //
    //eg2:AsciitoHex  in C
    //

    #include <stdio.h>

    void text_to_hex(char *is_ascii_string, char *os_hex_string, int ii_ascii_string_size);

    int main()
    {
       FILE *pf_in_file  = NULL;
       char ps_in_filename[20] = "";
       int  pi_input_chunk_size  = 0;
       char ps_input_chunk[161] = "";
       long pl_bytes_to_read = 160;
       char ls_input_chunk_raw[220] = "";

       strcpy(ps_input_chunk, "<8f><80>âY^SZÃpS  ðï^Y");
       pi_input_chunk_size = strlen(ps_input_chunk);

       printf("INput chunk   = [%s]/n", ps_input_chunk);
       printf("Read buf size = [%d]/n", pi_input_chunk_size);

       text_to_hex(ps_input_chunk, ls_input_chunk_raw, pi_input_chunk_size);

       printf("ls_input_chunk_raw = [%s]/n", ls_input_chunk_raw);

       return (0);
    }


    void text_to_hex(char *is_ascii_string, char *os_hex_string, int ii_ascii_string_size)
    {
       char *function = "text_to_hex";

       char   ls_hex[3] = "";
       int    i = 0;
       int    j = 0;

       memset(ls_hex, '/0', 3);

       j = 0;
       for (i=0; i < ii_ascii_string_size; i++)
       {
          sprintf(ls_hex, "%.2X", is_ascii_string[i]);

          os_hex_string[j++] = ls_hex[0];
          os_hex_string[j++] = ls_hex[1];
       }

       os_hex_string[j] = '/0';

    }
     

    ///
    //eg3.Convert the Ascii to Hex in C
    ///
    int main()
    {
        char symbols [] = "0123456789abcdef";
        char result [4];
        unsigned i, j, lsd, hexNum;
        for (i = 0; i < 256; ++i)
        {
            hexNum = i;
            j = 0;
            strcpy (result, "0");
            do
            {
                lsd = hexNum % 16;
                result [j++] = symbols [lsd];
                hexNum /= 16;
            } while (hexNum);
            result [j] = '/0';
            printf ("Hex: %s/n", _strrev (result));
        }
        return (0);
    }
     

    ///
    //eg4.
    ///
    cout<<hex<<(int)'tian'<<endl;//貌似这样也行。。
     
    ///
    //eg5. Transform a word into ASCII code
    ///

    #include <iostream>
    using namespace std;
    int main()
    {
        char word[32];
        int x = 0;
        cout << "Please enter the word (maximum 32 characters):/n";
        cin >> word;
        cout << "The ASCII for this word is:/n";
        while (word[x] != '/0')    // While the string isn't at the end...
        {
            cout << int(word[x]);    // Transform the char to int
            x++;
        }
        cout << "/n";
        return 0;
    }

    ///
    //eg6.
    ///
    #include <iostream>
    #include <string>
    #include <sstream>
    #include <iomanip>

    using namespace std;

    int main()
    {
     string val("54657374");
     stringstream ss(val);
     long l;
     ss >hex >l;
     cout << "val ='" << val << "', l = " << l << ", hex(l) ='" << hex << l << "'"<< endl;
     return 0;
    }

    ///
    //eg6. If you want to convert hex string into a number use strtol()
    ///
    #include <cstdlib>
    #include <cstdio>

    using namespace std;

    int main(int argc, char **argv)
    {
     if (argc==1)
     {
      fptus("need an argument/n", stderr);
      return 1;
     }

     while (--argc)
     {
      char *end;
      long num = strtol(*++argv, &end, 16);
      if (*end)
      {
       /* you could also add errno checking */
       fprintf(stderr, "%s: invalid number/n", *argv);
      }
      else
      {
       printf("%d/n", num);
      }
     } 
     return 0;
    }


    ///
    //eg7. One way is using stringstreams:
    ///

    #include <iostream>
    #include <cstdlib>
    #include <string>
    #include <sstream>

    std::string hex2DecString(std::string hexStr)
    {
     std::stringstream ss;

     // Read hexadecimal number into stream
     if (!(ss << std::hex << hexStr))
     {
      throw "hex2DecString: Conversion 1 error.";
     }

     // Read integer from stream
     int intVal;
     if (!(ss >intVal))
     {
      throw "hex2DecString: Conversion 2 error.";
     }

     // Read integer back into stream as decimal
     ss.clear(); // **See note below**
     ss.str("");
     if (!(ss << std::dec << intVal))
     {
      throw "hex2DecString: Conversion 3 error.";
     }

     // Extract decimal string of number
     return ss.str();
    }

    int main()
    {
     std::string hexStr = "1AB";
     std::string decStr = hex2DecString(hexStr);
     std::cout << "Hex = " << hexStr << "/tDecimal = " << decStr << std::endl;
     return EXIT_SUCCESS;
    }

     

    Table of ASCII Characters
    http://web.cs.mun.ca/~michael/c/ascii-table.html

    展开全文
  • C#程序用于ASCIIHEX转换工具,用C#重新写的ASCIIHEX代码互相转换的小工具,有点不稳定,只要格式正确使用就没什么问题.后会给出源代码.
  • 人生第一次写博客,工作几年,现在才想起来应该写点东西留点纪念,亡羊补牢,犹未为晚吧,渐渐把一些重要知识点整理起来,万事开头难,所以第一篇就整理几个转换函数,项目开发中总结的,编写者...char AsciiToHex(...

    人生第一次写博客,工作几年,现在才想起来应该写点东西留点纪念,亡羊补牢,犹未为晚吧,渐渐把一些重要知识点整理起来,万事开头难,所以第一篇就整理几个转换函数,项目开发中总结的,编写者不知呀╮(╯▽╰)╭,感谢无名者,已实际应用,这几个函数C语言中挺常用的,在单片机开发中也特别常用,特别是需要字符显示数据的时候,废话少说~~~~

    第一个,HEX转ASCII函数如下:

    int HexToAscii(unsigned char *pHexStr,unsigned char *pAscStr,int Len)
    {
    	char Nibble[2];
    	unsigned char Buffer[2048];
    	int i = 0;
    	int j = 0;
    
    	for(i=0;i<Len;i++)
    	{
    		Nibble[0]=pHexStr[i] >> 4 & 0X0F;
    		Nibble[1]=pHexStr[i] & 0x0F;
    		for(j=0;j<2;j++)
    		{
    			if(Nibble[j]<10)
    			{
    				Nibble[j]=Nibble[j]+0x30;
    			}
    			else if(Nibble[j]<16)
    			{
    				Nibble[j]=Nibble[j]-10+'A';
    			}
    			else
    			{
    				return 0;
    			}
    		}
    		memcpy(Buffer+i*2,Nibble,2);
    	}
    	Buffer[2*Len]=0x00;
    	memcpy(pAscStr,Buffer,2*Len);
    	pAscStr[2*Len]=0x00;
    	return 1;
    }
    }
    

    第二个,ASCII转HEX函数如下:

    char  AsciiToHex(unsigned char * pAscii, unsigned char * pHex, int nLen)
    {
    	int nHexLen = nLen / 2;
    	unsigned char Nibble[2] = {0};
    	int i = 0;
    	int j = 0;
    
    	if (nLen%2)
    	{
    		return 1;
    	}
    
    	for (i = 0; i < nHexLen; i ++)
    	{
    		Nibble[0] = *pAscii ++;		
    		Nibble[1] = *pAscii ++;
    		for (j = 0; j < 2; j ++)
    		{
    			if (Nibble[j] <= 'F' && Nibble[j] >= 'A')
    				Nibble[j] = Nibble[j] - 'A' + 10;
    			else if (Nibble[j] <= 'f' && Nibble[j] >= 'a')
    				Nibble[j] = Nibble[j] - 'a' + 10;
    			else if (Nibble[j] >= '0' && Nibble[j] <= '9')
    				Nibble [j] = Nibble[j] - '0';
    			else
    				return 1;//Nibble[j] = Nibble[j] - 'a' + 10;
    			
    		}	// for (int j = ...)
    		pHex[i] = Nibble[0] << 4;	// Set the high nibble
    		pHex[i] |= Nibble[1];	//Set the low nibble
    	}	// for (int i = ...)
    	return 0;
    }
    

    第三个,ASCII转DEC函数如下:

    char  AsciiToDec(unsigned char * pAscii, unsigned char * pHex, int nLen)
    {
    	int nHexLen = nLen / 2;
    	unsigned char Nibble[2] = {0};
    	int i = 0;
    	int j = 0;
    
    	if (nLen%2)
    	{
    		return 1;
    	}
    
    	for (i = 0; i < nHexLen; i ++)
    	{
    		Nibble[0] = *pAscii ++;		
    		Nibble[1] = *pAscii ++;
    		for (j = 0; j < 2; j ++)
    		{
    			Nibble [j] = Nibble[j] - '0';
    		}	// for (int j = ...)
    	
    		pHex[i] = Nibble[0] * 10;	// Set the high nibble
    		pHex[i] += Nibble[1];	//Set the low nibble
    	}	// for (int i = ...)
    	return 0;
    }
    

    第四个,四字节大小端转换函数:

    #define REVERSE(a) (((a) & 0xff) << 24 | ((a) & 0xff00) << 8 | ((a) & 0xff0000) >> 8 | ((a) & 0xff000000) >> 24)
    //32位数据四个字节大小端转换
    

    以上就是本次总结的几个函数,希望有需要的人可以拿去用。

    展开全文
  • 最近在研究ESC/POS 打印指令,时不时的就用到 ASCIIHex的相互转换ASCII HEX ASCII HEX ASCII HEX ASCII HEXNUL 00DEL 10Space 200 30SOH 01DC1 11! 211 31STX ...
  • C#程序用于ASCIIHEX转换工具源代码,使用VS2010编译工具编译.
  • ASCII HEX 互转小工具

    2018-09-29 12:49:38
    支持一整段数据的转换 例如 : 16进制 30 31 32 33 34 35 36 HEX 1 2 3 4 5 6 7
  • linux下ASCIIHEX的实现

    2021-05-17 10:30:07
    } /*ascii 转16进制数组,失败返回-1,成功返回0*/ int ascii2hex(const char *string,int length,uint8_t hex[],int *hexlen) { char src_arr[length+2];/*奇数个字符首位补‘0’,字符串结束符'\0',所以是+2*/ int...
  • Java ascii to hex

    千次阅读 2014-03-21 18:47:35
    表达 数字的ascii string 转换回原始的数字 public static final byte[] toHex (byte hash[]) {  byte[] bytes = new byte[hash.length/2];  int i;  int j = 0;  int len = ((int)(hash.length /
  • Hexascii字符串转换

    2021-05-19 15:55:47
    您需要同时使用2(十六进制...对于十六进制字符串中的每个2chars来执行此操作如果字符串字符只有0-9A-F,则这样做:#include #include int hex_to_int(char c){int first = c / 16 - 3;int second = c % 16;int result...
  • LabVIEW ASCiiHex转换

    2019-05-06 12:36:55
    包含 ASCiiHex互相转换,16进制&正常显示&2进制&10;进制转换,10转16进制转换
  • AsciiHex转换器

    2008-06-30 12:39:14
    ascii码转化为十六进制
  • 浅析Hexascii之间如何转换

    千次阅读 2018-06-19 21:43:21
    方法一:int Hex2Ascii(char* hex, char* ascii) { int len = strlen(hex), tlen, i, cnt; for (i = 0, cnt = 0, tlen = 0; i&lt;len; i++) { char c = toupper(hex[i]); if ...
  • 使用java实现hexascii码的转换

    千次阅读 2018-11-29 23:12:32
    几乎很少写JAVA代码,第一是确实不会,第二感觉JAVA写起来不爽(较python、golang),但总有万不得已必须要用...一、ASCII to Hex 这里是将ascii码转换为十六进制值,代码如下: private static String asciiToHe...
  • #include <iostream> using namespace std; // 获取字符串长度 unsigned int strlen(const char *str) { const char *cp = str;...int hex2char(uint8_t c) { return ((c >= '0') && (c <= '9'.
  • ASCIIHEX相互转换

    2011-11-05 00:14:49
    ASCIIHEX相互转换 ASCIIHEX相互转换 ASCIIHEX相互转换
  • 1 将整个ASCII类型的数组(byte[])解码为(string) byte[0]=65 byte[1]=66 string=AB Encoding.ASCII.GetString(receive_buf) 2.将整个ASCII类型的数组(byte[])解码为科学计数法(decimal) s[0] =57;s[1] = 46;s[2]...
  • hex码和ascii码的转换

    千次阅读 2017-01-09 17:48:25
    //0x00~0x0F转换为ASCII码 unsigned char hextoa(uchar dat) { if (dat ) return (dat+'0'); else return (dat+('A'-10)); } //0~9,A~F的ASCII码还原成0~15 unsigned char atohex(uchar dat) { if (dat )
  • ASCII码转HEX程序-labview

    2018-12-22 21:08:15
    labview2014版本,如有需要更低版本请私信。自己用到的,分享一下
  • HexToAsc ( unsigned char chHex , unsigned char * chAscH , unsigned char * chAscL ) { unsigned char chTemp ; chTemp = chHex >> 4 ; if ( chTemp >= 0 && chTemp 9 ) ...
  • 实例如下: [removed] var symbols = " !\"#$%&'()*+,-./0123456789:;<=>?@"; ...//Hex to ASCII function toAscii(str) { valueStr = str.toLowerCase(); var hex = "0123456789abcdef"; v
  • python byte,hexascii转换

    万次阅读 2018-08-16 08:58:13
    python 2.7.x: a = &quot;String&quot; a_byte = a.decode('hex') a = a.encode('hex') python 3.5以上: a = &quot;... a_byte = bytes.fromhex(a) ... a = a_byte.hex()
  • HexASCII相互转换函数

    万次阅读 2012-08-30 17:08:43
    char HexToASCII(unsigned char data_hex) {  char ASCII_Data;  ASCII_Data=data_hex & 0x0F;  if(ASCII_Data  ASCII_Data=ASCII_Data+0x30; //‘0--9’  else   ASCII_Data=ASCII_Data+0x37; /...
  • Ascii Coded heX Utility

    2012-09-14 22:49:42
    As standard pc hex editors are not able to load ascii-coded-hex contents like intel hex or motorola s-records, I wrote a basic tool to handle ascii-coded-hex for my own. By the time it grew to ja-tool...
  • Ascii Unicode Hex转码工具

    热门讨论 2012-10-31 11:50:30
    Ascii Unicode Hex转码工具,可以将数据从3种编码相互转换

空空如也

空空如也

1 2 3 4 5 ... 20
收藏数 30,482
精华内容 12,192
关键字:

AsciiToHex