LoginSignup
1
0

More than 5 years have passed since last update.

ASCII文字の16進表現の値を調べる各種の方法

Last updated at Posted at 2017-10-26

様々な方法で \n の16進表現を調べてみます。
例えば、 \n の16進表現は a(0xa
0x0a という表記もあり)です。

方法1 Googleで"man ascii"

方法2 LinuxやMacのターミナルで

$ man ascii

※ 表記の違いに注意
- Linux系の場合\nLF
- Macの場合、\nnl

方法3 Node.jsのREPLで

$ node
> console.log('\n'.charCodeAt(0).toString(16));
a

方法4 Rubyのワンライナーで

$ ruby -e 'p "\n".ord.to_s(16)'
"a"

方法5 Pythonのワンライナーで

$ python -c "print(hex(ord('\n')))"
0xa

方法6 Cで

cr.c
#include <stdio.h>

int main(void)
{
    printf("%x\n", '\n');
    return 0;
}

方法7 C++で

cr.cpp
#include <iostream>

int main()
{
    std::cout << std::hex << static_cast<int>('\n') << std::endl;
    return 0;
}
1
0
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
1
0