Monday, May 24, 2010

Can you make me a c language or source code for turbo C that can convert decimal to binary and vice versa?

guys please answer this... please............................ please make a single machine code that can convert decimal to binary, (example... press 1 to convert decimal to binary press 2 to convert binary to decimal..)

Can you make me a c language or source code for turbo C that can convert decimal to binary and vice versa?
Does your instructor want a flowchart and pseudocode too or just the working code?
Reply:a quick and dirty way:


int main() {


int myVal, sum=0, bPos=0,bVals[16]={32768,16384,...


char bStr[17]="0000000000000000"; Report It

Reply:printf("enter an integer (0-65535): ");


scanf("%d", %26amp;myVal);


sum = myVal;


while ( sum %26gt;= 0 ) {


if (sum %26gt; bVals[bPos]) {


sum -= bVals[bPos];


bStr[bPos]='1';}


bPos++;


}


printf("Binary is: %s\n", bStr);


return 0;


} Report It



No comments:

Post a Comment