문자를 숫자형으로 출력하면 아스키 코드가 나오기도 한다.
Bash
bash
read str
printf '%d\n' "'$str"
1
2
2
$str
앞의 따옴표는 뒤에 오는 문자를 아스키 코드로 출력하기 위해 넣어줘야 한다.
C
c
#include <stdio.h>
int main(void) {
char str;
scanf("%c", &str);
printf("%d\n", str);
return 0;
}
1
2
3
4
5
6
7
8
9
2
3
4
5
6
7
8
9
Node.js
javascript
let str = require("fs").readFileSync(0).toString().trim();
console.log( str.charCodeAt(0) );
1
2
2
PHP
php
<?php
fscanf(STDIN, "%c", $x);
echo ord($x);
?>
1
2
3
4
2
3
4
Python3
python
print(ord(input()))
1
Ruby
ruby
puts gets.chomp.ord
1
Comments
Not supported comment edit and upvote
You can do it on this page if you want.