Created
April 9, 2015 02:44
-
-
Save JHeld07/c3c7ba6a3690b8db7e2c to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include <stdio.h> | |
#include <conio.h> | |
#include <math.h> | |
/* Typing exercise | |
void binaryprint(int x); | |
main(){ | |
int input; | |
printf("please enter a number: "); | |
scanf(" %d", &input); | |
binaryprint(input); | |
while(!kbhit()){} | |
} | |
void binaryprint(int x){ | |
int mask=0x80; | |
while(mask>=0x01){ | |
if(mask==0x08){ | |
printf(" "); | |
} | |
if(x&mask){ | |
printf("1"); | |
} | |
else | |
printf("0"); | |
mask=mask>>1; | |
} | |
} | |
*/ | |
/* design 1 | |
void binaryprint(int x); | |
int binaryset(int x, int loc); | |
main(){ | |
int numb=0, loc=0; | |
//int mask=0x01; | |
binaryprint(numb); | |
numb=binaryset(numb, loc); | |
binaryprint(numb); | |
while(!kbhit()){} | |
} | |
void binaryprint(int x){ | |
int mask=0x80; | |
printf("\n"); | |
while(mask>=0x01){ | |
if(mask==0x08){ | |
printf(" "); | |
} | |
if(x&mask){ | |
printf("1"); | |
} | |
else | |
printf("0"); | |
mask=mask>>1; | |
} | |
} | |
int binaryset(int numb, int loc){ | |
int mask=0x01; | |
numb=numb|(mask<<loc); | |
return(numb); | |
} | |
*/ | |
/* | |
//Design 2 | |
void binaryprint(int x); | |
int binaryreset(int x, int loc); | |
int binaryset(int x, int loc); | |
main(){ | |
int numb=0xff, loc=0; | |
//int mask=0x01; | |
binaryprint(numb); | |
numb=binaryreset(numb, loc); | |
binaryprint(numb); | |
while(!kbhit()){} | |
} | |
void binaryprint(int x){ | |
int mask=0x80; | |
printf("\n"); | |
while(mask>=0x01){ | |
if(mask==0x08){ | |
printf(" "); | |
} | |
if(x&mask){ | |
printf("1"); | |
} | |
else | |
printf("0"); | |
mask=mask>>1; | |
} | |
} | |
int binaryset(int numb, int loc){ | |
int mask=0x01; | |
numb=numb|(mask<<loc); | |
return(numb); | |
} | |
int binaryreset(int numb, int loc){ | |
int mask = 0x80; | |
numb=numb&~(mask<<loc); | |
return(numb); | |
} | |
*/ | |
/* | |
//Design 3 | |
void binaryprint(int x); | |
int binaryreset1(int x, int loc); | |
int binaryset(int x, int loc); | |
int binarytoggle(int x, int loc); | |
main(){ | |
int numb=0xf0, loc; | |
//int mask=0x01; | |
binaryprint(numb); | |
loc=4; | |
numb=binaryreset1(numb, loc); | |
loc=7; | |
numb=binaryreset1(numb, loc); | |
loc=2; | |
numb=binarytoggle(numb, loc); | |
binaryprint(numb); | |
while(!kbhit()){} | |
} | |
void binaryprint(int x){ | |
int mask=0x80; | |
printf("\n"); | |
while(mask>=0x01){ | |
if(mask==0x08){ | |
printf(" "); | |
} | |
if(x&mask){ | |
printf("1"); | |
} | |
else | |
printf("0"); | |
mask=mask>>1; | |
} | |
} | |
int binaryset(int numb, int loc){ | |
int mask=0x01; | |
numb=numb|(mask<<loc); | |
return(numb); | |
} | |
int binaryreset1(int numb, int loc){ | |
int mask = 0x01; | |
numb=numb&(~(mask<<loc)); | |
return(numb); | |
} | |
int binarytoggle(int numb, int loc){ | |
int mask = 0x01; | |
numb=numb^(mask<<loc); | |
return(numb); | |
} | |
*/ | |
//Design 4 | |
/* | |
void binaryprint(int x); | |
void binaryprintb(int x); | |
int binaryreset1(int x, int loc); | |
int binaryset(int x, int loc); | |
int binarytoggle(int x, int loc); | |
main(){ | |
int numb=0xa0, loc; | |
//int mask=0x01; | |
binaryprint(numb); | |
binaryprintb(numb); | |
while(!kbhit()){} | |
} | |
void binaryprint(int x){ | |
int mask=0x80; | |
printf("\n"); | |
while(mask>=0x01){ | |
if(mask==0x08){ | |
printf(" "); | |
} | |
if(x&mask){ | |
printf("1"); | |
} | |
else | |
printf("0"); | |
mask=mask>>1; | |
} | |
} | |
void binaryprintb(int x){ | |
int mask=0x01; | |
printf("\n"); | |
while(mask<=0x80){ | |
if(mask==0x08){ | |
printf(" "); | |
} | |
if(x&mask){ | |
printf("1"); | |
} | |
else | |
printf("0"); | |
mask=mask<<1; | |
} | |
} | |
*/ | |
//design 5 | |
/* | |
void binaryprint(int x); | |
main(){ | |
int input; | |
printf("please enter a number: "); | |
scanf(" %d", &input); | |
binaryprint(input); | |
} | |
void binaryprint(int x){ | |
int mask=0x01; | |
if((x&mask)==1){ | |
printf("odd"); | |
} | |
else | |
printf("even"); | |
while(!kbhit()){} | |
} | |
*/ | |
//problem 6 | |
void binaryprint(int x); | |
int binaryreset1(int x, int loc); | |
int binaryset(int x, int loc); | |
int binarytoggle(int x, int loc); | |
main(){ | |
int numb=0x00, loc; | |
//int mask=0x01; | |
printf("Start: "); | |
binaryprint(numb); | |
printf("\nEnter the bit number you want to change 0-7\n"); | |
scanf(" %d", &loc); | |
numb=binaryset(numb, loc); | |
binaryprint(numb); | |
while(!kbhit()){} | |
} | |
void binaryprint(int x){ | |
int mask=0x80; | |
printf("\n"); | |
while(mask>=0x01){ | |
if(mask==0x08){ | |
printf(" "); | |
} | |
if(x&mask){ | |
printf("1"); | |
} | |
else | |
printf("0"); | |
mask=mask>>1; | |
} | |
} | |
int binaryset(int numb, int loc){ | |
int mask=0x01; | |
numb=numb|(mask<<loc); | |
return(numb); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment