Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How can I get the ascii decimal values of characters in Clojure?

user=> (char 65)
\A
user=> (char 97)
\a
user=> (str (char 65))
"A"
user=> (str (char 97))
"a"

These are the characters from the ascii decimal values ... How do I get the ascii decimal values from the characters?

like image 927
logigolf Avatar asked Nov 08 '11 02:11

logigolf


People also ask

How do I get the ASCII value of a character in Perl?

The ord() function is an inbuilt function in Perl that returns the ASCII value of the first character of a string. This function takes a character string as a parameter and returns the ASCII value of the first character of this string.

How do I get the ASCII value of a character?

Example: Find ASCII value of a character Now, to find the ASCII value of ch , we just assign ch to an int variable ascii . Internally, Java converts the character value to an ASCII value. We can also cast the character ch to an integer using (int) .

What is the ASCII code corresponds to decimal?

ASCII stands for American Standard Code for Information Interchange. It ranges from 0 to 255 in Decimal or 00 to FF in Hexadecimal.

What is the ASCII value of special characters?

Special Characters(32–47 / 58–64 / 91–96 / 123–126): Special characters include all printable characters that are neither letters nor numbers. These include punctuation or technical, mathematical characters.


2 Answers

user=> (doseq [c "aA"] (printf "%d%n" (int c)))
97
65
nil
user=> (map int "aA");;
(97 65)
user=> (apply str (map char [97 65]))
"aA"
like image 110
BLUEPIXY Avatar answered Nov 09 '22 14:11

BLUEPIXY


A character is a number, it's just that clojure is showing it to you as a char. The easiest way is to just cast that char to an int.

e.g.

user=> (int \A)
65
user=> (int (.charAt "A" 0))
65
like image 40
Bill Avatar answered Nov 09 '22 15:11

Bill