Why HTML decimal and HTML hex?

泪湿孤枕 提交于 2019-12-21 12:18:16

问题


I have tried to Google quite a while now for an answer why HTML entities can be compiled either in HTML decimal or HTML hex. So my questions are:

  • What is the difference between HTML decimal and HTML hex?
  • Why are there two systems to do the same thing?

回答1:


Originally, HTML was nominally based on SGML, which has decimal character references only. Later, the hexadecimal alternative was added in HTML 4.01 (and soon implemented in browsers), then retrofitted into SGML in the Web Adaptations Annex.

The apparent main reason for adding the hexadecimal alternative was that all modern character code and encoding standards, such as Unicode, use hexadecimal notation for the code numbers of characters. The ability to refer to a character by its Unicode number, written in the conventional hexadecimal notation, just prefixed with &#x and suffixed with ;, helps to avoid errors that may arise if people convert from hexadecimal to decimal notation.




回答2:


There are three radixes used in computer technologies:

  • Binary, radix 2, because ultimately integers are arrays of switches, each which may be on (1) or off (0).
  • Octal, radix 8, because each digit represents exactly 3 bits, so it's easy to convert to binary.
  • Decimal, radix 10, because humans have 10 fingers and because we grew up using this radix.
  • Hexadecimal, radix 16, because like octal it's easy to convert to bits, but even better because 2 hex digits can be expressed in exactly 1 byte. If, for example, you see an rgba value given in hex as 0x00ff00ff, you can see instantly that it represents opaque green.

So, to answer the question posed, for some of us hex is the natural way to express integers as it gives more insight into the storage. For others it's decimal. To each his or her own!

Finishing with an HTML example: could &65536; be a character of utf-16? In hex it's easy to see that the answer is no, because its the same as &x10000; which needs more than 16 bits.



来源:https://stackoverflow.com/questions/17425555/why-html-decimal-and-html-hex

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!