What is an ordinal value of a String? [closed]

天涯浪子 提交于 2019-11-28 01:11:43

问题


I'm confused about the term Ordinal value of a character or a string in php documentation. Can somebody tell me what exactly an ordinal value is?


回答1:


One "character" in PHP is one byte. Note that this is misleading for multi-byte characters, in which one character (say "漢") is encoded in multiple bytes. Anyway though, a byte is 8 bits and can represent a number between 0 and 255. The ordinal value of a character byte is simply this numerical value.

ord('a') -> 97

Read http://kunststube.net/encoding if you need more background information about bytes/characters/encodings.




回答2:


Ordinal value is Nothing but the ASCII value of a character And as we know every character takes one byte i.e. 8 bits and every bit can have either 0 or 1 as the possible value so every bit can have 2 values thus 8 positions can have power(2,8) = 256 combinations and every combination resembles 1 character like

00000000 => Null(0)

00010000 => Space(32)

(65 - 91) in Ascii => a-z

(97 - 122) in Ascii => (A-Z)

and (48 - 57) in Ascii => (0 - 9)

other combinations are assigned to other special chacater.

PHP have an inbuilt Function ord('a') which takes character as an argument and returns its ascii value i.e. 65 in this case




回答3:


The Ordinal Value of a character is nothing but the numeric location of a character.



来源:https://stackoverflow.com/questions/19174563/what-is-an-ordinal-value-of-a-string

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