0

I am learning php language. I was reading an article on php language and came across usage of different number systems namely decimal, hexadecimal, and octal numbers. We use decimal numbers and I know this that computers feed on Binary(0 and 1). So where does the Hex and the Octal number systems come into play in context of computers and programming?

Joy Grewal
  • 67
  • 6
  • different numbering systems are used by different algorithms. there are some performance tricks available in hex that don't work the same way in decimal. – xeo Mar 28 '17 at 08:33
  • 2
    @xeo That ... doesn't really make sense. Under the hood numbers are all stored as bits (binary). You can't get performance improvements, the bases are merely a different way of displaying the same thing. Different bases are really only there in the source code or when you actually display something as text on screen (in which case it's usually displayed as decimal). – uliwitness Mar 28 '17 at 09:19

1 Answers1

2

Computer people have to deal with how things are stored on the bit-level sometimes.

Hexadecimal is nice because it aligns with bytes: Whereas it is not immediately obvious how many bytes you need to store the decimal number 1234 (let alone what bits each of those bytes would contain), 0x1234 represents two bytes, 0x123456 three bytes. So you can read it byte-by-byte (two hex digits at a time).

Similarly, octal was useful on ancient systems that had 12-bit words.

Thilo
  • 257,207
  • 101
  • 511
  • 656