Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Methods like ord and chr from Python

Do you know any functions that would preform the same as ord and chr from Python in Java.

Python docs on them.

  • http://docs.python.org/2/library/functions.html#ord
  • http://docs.python.org/2/library/functions.html#chr

I've experienced manually but seem to get so many errors. This would need to work with Strings not just char. Figured I would see if there was a function to do it pre-built.

Thanks

like image 751
Kyle93 Avatar asked Nov 27 '13 18:11

Kyle93


People also ask

What is CHR () and Ord () in Python?

Python chr() and ord() Python's built-in function chr() is used for converting an Integer to a Character, while the function ord() is used to do the reverse, i.e, convert a Character to an Integer.

What are the use of Ord () and CHR () function in Python explain with example?

Python ord() and chr() are built-in functions. They are used to convert a character to an int and vice versa. Python ord() and chr() functions are exactly opposite of each other.

What does CHR () do in Python?

The chr() function returns the character that represents the specified unicode.

What is ord (' A ') in Python?

Python ord() example For example, ord('a') returns the integer 97, ord('€') (Euro sign) returns 8364. This is the inverse of chr() for 8-bit strings and of unichr() for Unicode objects. If a Unicode argument is given and Python is built with UCS2 Unicode, then the character's code point must be in the range [0..


1 Answers

You can cast:

c = (char) n;

n = (int) c;
like image 165
Simeon Visser Avatar answered Sep 22 '22 13:09

Simeon Visser