如何用C来比较十六进制值? [英] How to compare hex values using C?
问题描述
我与十六进制值工作。到现在为止,我知道如何打印十六进制值,也precision的事情。现在我要比较的十六进制值。例如我从文件中读取数据到一个字符缓冲区。现在我想数据的十六进制值比较缓冲区。是否有这样的事?
I am working with hex values. Until now I know how to print hex values and also precision thing. Now I want to compare the hex values. For example I am reading data from a file into a char buffer. Now I want to compare the hex value of data in the buffer. Is there anything like this?
if hex(buffer[i]) > 0X3F
then
//do somthing
我怎样才能做到这一点?
How can I do this?
推荐答案
您快到了:
if (buffer[i] > 0x3f)
{
// do something
}
请注意,没有必要转换任何六角 - 你可以直接比较字符或整数值,因为一个十六进制常量如0x3F的是另一种psenting一个整数值,再$ P $的方式。 0x3F的== 63(十进制)== ASCII?。
Note that there is no need to "convert" anything to hex - you can just compare character or integer values directly, since a hex constant such as 0x3f is just another way of representing an integer value. 0x3f == 63 (decimal) == ASCII '?'.
这篇关于如何用C来比较十六进制值?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!