Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

Tags:

php

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?

like image 975
Suraj Adhikari Csit Oriento Avatar asked Oct 04 '13 06:10

Suraj Adhikari Csit Oriento


People also ask

When should I use the ordinal property of a string?

This is most appropriate when comparing strings that are generated programmatically or when comparing case-sensitive resources such as passwords. The Ordinal property actually returns an instance of an anonymous class derived from the StringComparer class. Gets the value associated with the specified key.

What is the ordinal value of a character?

The Ordinal Value of a character is nothing but the numeric location of a character. Not the answer you're looking for? Browse other questions tagged php or ask your own question.

What is ordinal data in statistics?

Ordinal data are categorical (non-numeric) but may use numbers as labels. Ordinal data are always placed into some kind of hierarchy or order (hence the name ‘ordinal’—a good tip for remembering what makes it unique!) While ordinal data are always ranked, the values do not have an even distribution.

What is the difference between nominal and ordinal data?

While nominal and ordinal variables are categorical, interval and ratio variables are quantitative. Nominal data differs from ordinal data because it cannot be ranked in an order.


2 Answers

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.

like image 143
deceze Avatar answered Oct 06 '22 19:10

deceze


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

like image 26
Amber Sharma Avatar answered Oct 06 '22 19:10

Amber Sharma