简体   繁体   English

计算机如何比较十六进制和十进制值

[英]how does the computer compare the hexadecimal and decimal values

I was looking through an existing code in C wherein there is a check for no's in a particular range 100 to 899. I wanted to add one more condition along with that the no can have the value 1FE. 我正在查看C中的现有代码,其中检查是否在100到899的特定范围内。我想再加上一个条件,使否的值可以为1FE。 I should not convert it to a decimal no. 我不应该将其转换为十进制数字。 But I need to check for this hexadecimal value. 但是我需要检查这个十六进制值。 My doubt here is, How will the hardware interpret the comparision of the decimal and the hexadecimal. 我的疑问是,硬件将如何解释十进制和十六进制的比较。 The hardware will interpret the values in zero's and one's. 硬件将解释零和一的值。 So will it convert the decimal and hexadecimal no's to binary to check the value ? 那么它将把十进制和十六进制的no转换为二进制以检查值吗? (As 1FE when converted to decimal is 510 which will be included within the no 899).Please help to understand. (由于1FE转换为十进制时为510,因此将包含在899号中)。请帮助理解。

int x = 0x1fe; and int x = 510; 并且int x = 510; are the exact same thing to the computer (or more specifically, to the compiler -- the actual hardware will never see "0x1fe" or "510" -- it will only see the binary version) so your question doesn't make much sense. 与计算机完全相同(或更具体地说,对于编译器-实际硬件永远不会看到“ 0x1fe”或“ 510”-它只会看到二进制版本),所以您的问题没有多大意义。

Changing the base only changes the representation of a value; 更改基数只会更改值的表示形式; it doesn't change the actual value. 它不会改变实际值。 If you have 101 2 apples, and you have 5 10 apples, you still have the same amount of apples. 如果您有101 2个苹果,并且有5 10个苹果,则您仍然有相同数量的苹果。

The representation computers use just happens to be binary. 计算机使用的表示形式恰好是二进制的。 (Well, doesn't 'just happen' to be, but.... yeah.) (嗯,不是“恰好”发生,而是..是的。)

My doubt here is, How will the hardware interpret the comparision of the decimal and the hexadecimal. 我的疑问是,硬件将如何解释十进制和十六进制的比较。

The hardware has no notion of decimal or hexadecimal. 硬件没有十进制或十六进制的概念。 To the machine 0x1FE and 510 are indistinguishable; 对于机器,0x1FE和510是无法区分的; they are simply two different representations of exactly the same thing. 它们只是完全相同的事物的两种不同表示。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM