Develop
2003.04.23 11:01
[c] 정수를 2진수로 변환 (재귀,비트연산)
조회 수 7603 댓글 0
정수를 이진수로 변환
## 재귀함수 호출에 의한 변환 ##
-------------------------------------------------------------------
#include<stdio.h>
void bin(int num){
if(num<1) return;
bin(num/2);
printf("%d", num%2);
}
void main(){
int num;
printf("Enter a Number : ");
scanf("%d", &num);
bin(num);
printf("\n");
}
-------------------------------------------------------------------
## mask에 의한 쉬프트/비트 연산에 의한 변환 ##
-------------------------------------------------------------------
#include<stdio.h>
void main(){
unsigned char num;
unsigned char mask=128;
int i;
printf("Enter a Number : ");
scanf("%d", &num);
printf("%d\n", num);
if(mask&num) printf("-");
else printf("+");
for(i=0; i<7; i++){
mask = mask >> 1;
if(mask&num) printf("1");
else printf("0");
}
printf("\n");
}
-------------------------------------------------------------------
번호 | 분류 | 제목 | 글쓴이 | 날짜 | 조회 수 |
---|---|---|---|---|---|
993 | Develop | [git] 쉬운 버전관리 Git 설명 | hooni | 2015.08.18 | 951 |
992 | Develop | [ios] 오브젝티브C→스위프트, 코드 변환 손쉽게 | hooni | 2015.08.07 | 1069 |
991 | Develop | [ios] Objective-C Types & Storage Capacity | hooni | 2015.07.22 | 1254 |
990 | PPT | [ppt] Macro for board game 발표자료 (@Team Study 2013.01.18) 1 | hooni | 2015.07.22 | 1370 |
989 | PPT | [ppt] Information Security 발표 자료 (@Team Study 2012.11.15) | hooni | 2015.07.22 | 959 |
988 | PPT | [ppt] Equation Solving 발표 자료 (@AjaxUI랩 밋업데이 2012.02.28) | hooni | 2015.07.22 | 989 |
987 | Develop | [ios] AES256 알고리즘을 이용해 데이터 암호화/복호화 방법 | hooni | 2015.07.21 | 4180 |
986 | System/OS | 맥 OS X 에서 스크린 화면 캡쳐 단축키 (Mac Print Screen) | hooni | 2015.07.21 | 2030 |
985 | Develop | [ios] NSData to NSString (NSString to NSData) | hooni | 2015.07.21 | 726 |
984 | Develop | [ios] WWDC 2015 샘플 소스 코드 통합파일 | hooni | 2015.07.20 | 797 |
983 | Develop | [android] N-Puzzle 게임 | hooni | 2015.07.09 | 953 |
982 | System/OS | [windows] 윈도우 사용자 계정 로그인 암호 분실, 암호 변경하는 방법 | hooni | 2015.07.09 | 21512 |