需要将char转换为hexadecmial值 [英] need to convert a char to an hexadecmial value

查看:76
本文介绍了需要将char转换为hexadecmial值的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述



我需要帮助才能将字符转换为对应的
十六进制值,如下例所示,

ASCII值: ABC

十六进制代码值:%41%42%43 ...


转换逻辑是什么......

解决方案


sa ***** @ yahoo .co.in 写道:


我需要帮助将角色转换成对应的十六进制值


使用以下作为示例。


问候,

拉尔夫


#include < stdio.h>


int main(无效)

{

char c ='''';

char hex [4];

char * hp =& hex [1];

hex [0] =''%'';

hex [3] =''\ 0'';


snprintf(hp,3,"%x",c);

printf("%s \ n",hex);

返回0;

}


-

Ralph Moritz


嘲笑你的问题;其他人都这样做。


sa ***** @ yahoo.co.in 写道:


我需要帮助将字符转换为对应的十六进制值,如下例所示,
ASCII值:ABC
十六进制代码值:%41%42%43 ......
什么是转换逻辑......



#include< stdio.h>

#include< stdlib.h>


int main(void){

char arr [3] = {''A'',''B'',''C''};

短cnt;


for(cnt = 0; cnt< 3; cnt ++)

printf(" %%% x",arr [cnt]);


fflush(stdout);

返回0;

}


2006 -03-27, sa*****@yahoo.co.in < sa ***** @ yahoo.co.in>写道:


我需要帮助将字符转换为对应的十六进制值,如下例所示,
ASCII值:ABC
Hex代码值:%41%42%43 ......

什么是转换的逻辑...




1)学习如何沿着一个字符串步骤例如


for(int i = 0; i< strlen(s); i ++)

char myChar = s [i];


2)在c参考中查找如何使用程序转换值

如printf和sprintf。


3)查找%。1s。 printf / sprintf的类型格式说明符

祝你好运!


Hi,
I needed help in converting a character to the correspoding
hexadecimal values, like the following example,
ASCII value : ABC
Hex Code Value : %41%42%43...

whats the logic of conversion...

解决方案


sa*****@yahoo.co.in wrote:

Hi,
I needed help in converting a character to the correspoding
hexadecimal values



Use the following as an example.

Regards,
Ralph

#include <stdio.h>

int main(void)
{
char c = '' '';
char hex[4];
char *hp = &hex[1];
hex[0] = ''%'';
hex[3] = ''\0'';

snprintf(hp, 3, "%x", c);
printf("%s\n", hex);
return 0;
}

--
Ralph Moritz

Laugh at your problems; everybody else does.


sa*****@yahoo.co.in wrote:

Hi,
I needed help in converting a character to the correspoding
hexadecimal values, like the following example,
ASCII value : ABC
Hex Code Value : %41%42%43...

whats the logic of conversion...



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

int main(void) {
char arr[3] = { ''A'', ''B'', ''C'' };
short cnt;

for(cnt = 0; cnt < 3; cnt++)
printf("%%%x ", arr[cnt]);

fflush(stdout);
return 0;
}


On 2006-03-27, sa*****@yahoo.co.in <sa*****@yahoo.co.in> wrote:

Hi,
I needed help in converting a character to the correspoding
hexadecimal values, like the following example,
ASCII value : ABC
Hex Code Value : %41%42%43...

whats the logic of conversion...



1) learn how to step along a string e.g

for(int i=0;i<strlen(s);i++)
char myChar = s[i];

2) look up in the c reference how to convert values using programs
like printf and sprintf.

3) look up the "%.1s" type format specifier for printf/sprintf

good luck!


这篇关于需要将char转换为hexadecmial值的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆