"함수 dechex()"의 두 판 사이의 차이

 
(사용자 2명의 중간 판 21개는 보이지 않습니다)
1번째 줄: 1번째 줄:
[[분류: 16진수]]
[[분류: 변환]]
==개요==
==개요==
;hex
;hex
;dechex
;dechex()
;.toHexString()
*decimal to hexadecimal
*decimal to hexadecimal
*10진수 → 16진수
*10진수 → 16진수
7번째 줄: 11번째 줄:
==Bash==
==Bash==
[[category: Bash]]
[[category: Bash]]
<source lang='Bash'>
<syntaxhighlight lang='Bash' run>
printf %x 10
printf "%x\n" 10   # a
# a
printf "%x\n" 47   # 2f
printf %x 47
printf "%x\n" 65535 # ffff
# 2f
</syntaxhighlight>
printf %x 65535
<syntaxhighlight lang='Bash' run>
# ffff
result=$(printf %x 65535)
</source>
echo $result # ffff
<source lang='Bash'>
</syntaxhighlight>
result=`printf %x 65535`
<syntaxhighlight lang='bash'>
echo $result
echo "obase=16; 10" | bc
# ffff
# A
</source>
echo "obase=16; 47" | bc
# 2F
echo "obase=16; 65535" | bc
# FFFF
</syntaxhighlight>
 
==Java==
[[분류: Java]]
 
{{참고|자바 Integer.toHexString()}}
<syntaxhighlight lang='java'>
System.out.println( Integer.toHexString(10) );
System.out.println( Integer.toHexString(47) );
System.out.println( Integer.toHexString(65535) );
// a
// 2f
// ffff
</syntaxhighlight>
 
{{참고|자바 Long.toHexString()}}
<syntaxhighlight lang='java'>
System.out.println( Long.toHexString(4294967295L) );
System.out.println( Long.toHexString(1234567890123456L) );
// ffffffff
// 462d53c8abac0
</syntaxhighlight>


==PHP==
==PHP==
{{참고|PHP dechex()}}
[[category: PHP]]
[[category: PHP]]
<source lang='PHP'>
<syntaxhighlight lang='PHP' run>
echo dechex(10); // a
echo dechex(10)   . "\n"; # a
echo dechex(47); // 2f
echo dechex(47)   . "\n"; # 2f
</source>
echo dechex(65535) . "\n"; # ffff
</syntaxhighlight>


==Python==
==Python==
{{참고|Python hex()}}
[[category: Python]]
[[category: Python]]
<source lang='Python'>
<syntaxhighlight lang='Python' run>
print( hex(10) ) # 0xa
print( hex(10) )   # 0xa
print( hex(47) ) # 0x2f
print( hex(47) )   # 0x2f
print( hex(65535) ) #0xffff
print( hex(65535) ) # 0xffff
</source>
</syntaxhighlight>


==같이 보기==
==같이 보기==
*[[HEX]]
*[[HEX]]
*[[hexdec]]
*[[함수 hexdec()]]
*[[16진수]]
*[[16진수]]

2021년 4월 21일 (수) 23:25 기준 최신판


1 개요[ | ]

hex
dechex()
.toHexString()
  • decimal to hexadecimal
  • 10진수 → 16진수

2 Bash[ | ]

printf "%x\n" 10    # a
printf "%x\n" 47    # 2f
printf "%x\n" 65535 # ffff
result=$(printf %x 65535)
echo $result # ffff
echo "obase=16; 10" | bc
# A
echo "obase=16; 47" | bc
# 2F
echo "obase=16; 65535" | bc
# FFFF

3 Java[ | ]

System.out.println( Integer.toHexString(10) );
System.out.println( Integer.toHexString(47) );
System.out.println( Integer.toHexString(65535) );
// a
// 2f
// ffff
System.out.println( Long.toHexString(4294967295L) );
System.out.println( Long.toHexString(1234567890123456L) );
// ffffffff
// 462d53c8abac0

4 PHP[ | ]

echo dechex(10)    . "\n"; # a
echo dechex(47)    . "\n"; # 2f
echo dechex(65535) . "\n"; # ffff

5 Python[ | ]

print( hex(10) )    # 0xa
print( hex(47) )    # 0x2f
print( hex(65535) ) # 0xffff

6 같이 보기[ | ]

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