"함수 base16 encode()"의 두 판 사이의 차이

 
(같은 사용자의 중간 판 2개는 보이지 않습니다)
4번째 줄: 4번째 줄:


==Bash==
==Bash==
[[분류: Bash]]
<syntaxhighlight lang='bash'>
<syntaxhighlight lang='bash'>
echo -n 'hello world' | xxd -p
echo -n 'hello world' | xxd -p
# 68656c6c6f20776f726c64
</syntaxhighlight>
<syntaxhighlight lang='bash'>
echo -n 'hello world' | hexdump -e '"%x"'
# 68656c6c6f20776f726c64
# 68656c6c6f20776f726c64
</syntaxhighlight>
</syntaxhighlight>
12번째 줄: 15번째 줄:
echo -n '★A가あ中' | xxd -p
echo -n '★A가あ中' | xxd -p
# e2988541eab080e38182e4b8ad
# e2988541eab080e38182e4b8ad
</syntaxhighlight>
==Python==
<syntaxhighlight lang='python'>
s = 'hello world'
print(''.join(f'{ord(c):x}' for c in s))
# 68656c6c6f20776f726c64
</syntaxhighlight>
<syntaxhighlight lang='python'>
s = 'hello world'
print(''.join(hex(ord(c))[2:] for c in s))
# 68656c6c6f20776f726c64
</syntaxhighlight>
<syntaxhighlight lang='python'>
s = 'hello world'
print(''.join('{:x}'.format(ord(c)) for c in s))
# 68656c6c6f20776f726c64
</syntaxhighlight>
</syntaxhighlight>



2022년 12월 11일 (일) 01:09 기준 최신판

1 개요[ | ]

함수 base16_encode()

2 Bash[ | ]

echo -n 'hello world' | xxd -p
# 68656c6c6f20776f726c64
echo -n 'hello world' | hexdump -e '"%x"'
# 68656c6c6f20776f726c64
echo -n '★A가あ中' | xxd -p
# e2988541eab080e38182e4b8ad

3 Python[ | ]

s = 'hello world'
print(''.join(f'{ord(c):x}' for c in s))
# 68656c6c6f20776f726c64
s = 'hello world'
print(''.join(hex(ord(c))[2:] for c in s))
# 68656c6c6f20776f726c64
s = 'hello world'
print(''.join('{:x}'.format(ord(c)) for c in s))
# 68656c6c6f20776f726c64

4 같이 보기[ | ]

문서 댓글 ({{ doc_comments.length }})
{{ comment.name }} {{ comment.created | snstime }}