简体   繁体   中英

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. 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 ? (As 1FE when converted to decimal is 510 which will be included within the no 899).Please help to understand.

int x = 0x1fe; and 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.

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.

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; they are simply two different representations of exactly the same thing.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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