Why use hex?

前端 未结 12 2033
你的背包
你的背包 2020-11-28 03:45

Hey! I was looking at this code at http://www.gnu.org/software/m68hc11/examples/primes_8c-source.html

I noticed that in some situations they used hex numbers, like i

12条回答
  •  不知归路
    2020-11-28 04:09

    Generally the use of Hex numbers instead of Decimal it's because the computer works with bits (binary numbers) and when you're working with bits also is more understandable to use Hexadecimal numbers, because is easier going from Hex to binary that from Decimal to binary.

    OxFF = 1111 1111 ( F = 1111 )
    

    but

    255 = 1111 1111 
    

    because

    255 / 2 = 127 (rest 1)
    127 / 2 = 63 (rest 1)
    63 / 2 = 31 (rest 1)
    ... etc
    

    Can you see that? It's much more simple to pass from Hex to binary.

提交回复
热议问题