"2진수의 특정 자리수 출력"의 두 판 사이의 차이

잔글 (봇: 자동으로 텍스트 교체 (-source +syntaxhighlight))
 
(사용자 2명의 중간 판 8개는 보이지 않습니다)
3번째 줄: 3번째 줄:


==C==
==C==
[[분류: C]]
<syntaxhighlight lang='c'>
<source lang='c'>
#include <stdio.h>
#include <stdio.h>
int main() {
int main() {
15번째 줄: 14번째 줄:
     printf("%d\n", (x>>0)&1); // 1
     printf("%d\n", (x>>0)&1); // 1
}
}
</source>
</syntaxhighlight>
 
==PHP==
<syntaxhighlight lang='php'>
<?php
$x = 0b111001;
$temp = decbin($x);
echo $temp{0} . "\n"; // 1
echo $temp{1} . "\n"; // 1
echo $temp{2} . "\n"; // 1
echo $temp{3} . "\n"; // 0
echo $temp{4} . "\n"; // 0
echo $temp{5} . "\n"; // 1
</syntaxhighlight>
 
==같이 보기==
* [[비트 다루기]]
 
[[분류: C]]
[[분류:PHP]]
[[분류:비트]]

2020년 11월 2일 (월) 02:34 기준 최신판

1 개요[ | ]

2진수의 특정 자리수 출력

2 C[ | ]

#include <stdio.h>
int main() {
    int x = 0b111001;
    printf("%d\n", (x>>5)&1); // 1
    printf("%d\n", (x>>4)&1); // 1
    printf("%d\n", (x>>3)&1); // 1
    printf("%d\n", (x>>2)&1); // 0
    printf("%d\n", (x>>1)&1); // 0
    printf("%d\n", (x>>0)&1); // 1
}

3 PHP[ | ]

<?php
$x = 0b111001;
$temp = decbin($x);
echo $temp{0} . "\n"; // 1
echo $temp{1} . "\n"; // 1
echo $temp{2} . "\n"; // 1
echo $temp{3} . "\n"; // 0
echo $temp{4} . "\n"; // 0
echo $temp{5} . "\n"; // 1

4 같이 보기[ | ]

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