함수 decbin()

Jmnote (토론 | 기여)님의 2019년 11월 13일 (수) 20:30 판 (→‎Python)
decimal to binary
decbin
bin

1 JavaScript

console.log( 6..toString(2) ); // 110
console.log( 104..toString(2) ); // 1101000
console.log( (+"6").toString(2) ); // 110
console.log( (+"104").toString(2) ); // 1101000
var a = 6;
var b = 104;
console.log( a.toString(2) ); // 110
console.log( b.toString(2) ); // 1101000
var a = "6";
var b = "104";
console.log( (+a).toString(2) ); // 110
console.log( (+b).toString(2) ); // 1101000

2 PHP

echo decbin(6);
// 110

3 Python

d = 10
b = f'{decimal:b}'
print( b )
# 1010
print( type(b) )
# <class 'str'>
d = 10
b = '{0:b}'.format(d)
print( b )
# 1010
print( type(b) )
# <class 'str'>
d = 10
b = bin(d)
print( b )
# 0b110
print( type(b) )
# <class 'str'>

4 같이 보기

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