int main(void) { int m; scanf("%*d"); while (scanf("%d", &m) == 1) printf("%d %d\n", dectobin(m), dectobin(hextodec(m))); return 0; }
void main(int argc,char *argv[]) { //printf("\nconvert %s %s %s \n",argv[1],argv[2],argv[3]); int b1=atoi(argv[1]),b2=atoi(argv[2]),i,size,m,n,check,dec,num; size=strlen(argv[3]); char s[size]; strcpy(s,argv[3]); check=checkb1(s,size,b1); if(check==1) { if(b1==b2) { printf("%s",argv[3]); } else if((b1==16||b1==2||b1==8)&&b2==10) // all to decimal { dec=alltodec(s,size,b1); printf("%d",dec); } else if(b1==10 && b2==2) // decimal to binary { num=atoi(s); dectobin(num); } else if((b1==16||b1==8)&&b2==2)// rest to binary { num=alltodec(s,size,b1); dectobin(num); } else if(b1==10&& b2==8) //decimal to octal { num=atoi(s); dectoct(num); } else if((b1==16||b1==2)&&b2==8) //rest to octal { num=alltodec(s,size,b1); dectoct(num); } else if(b1==10 && b2==16) // decimal to hexa { num=atoi(s); dectohex(num); } else if((b1==2||b1==8)&&b2==16) // rest to hexa { num=alltodec(s,size,b1); dectohex(num); } } }
void main() { int num; printf("\n enter a number = "); scanf("%d", &num); dectobin(num); }
/*解法1递归程序*/ void dectobin(int n) { if(n == 0) {printf("0"); return ;} if(n == 1) {printf("1"); return ;} if(n == 2) {printf("10"); return ;}/*此处三个判断排除测试点为0,即输入的时候n=0的数据*/ dectobin(n / 2); printf("%d",n % 2); }
int main(){ unsigned long long n, num; printf("Enter the decimal number: "); scanf("%llu",&n); num = dectobin(n); printf("The binary number is %llu\n",num); return 0; }
Json::Value CCmdBufferLengthCaseReceiver::Action() { Json::Value value; Json::Value ArgArray; char Shellbuf[4096]; string tShellbuf; string mCmdIndexString; FILE *pp; stringstream streamIndex, streamBufferLength; if((pp=popen("sudo find /home/vli/debugfs/mmc0 -name myTest","r")) == NULL){ std::cout << "Popen() error: " << std::endl; } if (mCmdname == set_m_delay) { mBufferLength = atoi(dectobin(mBufferLength).c_str()); //dectobin(mBufferLength); } streamIndex << setfill('0') << setw(10) << mCmdname; streamBufferLength << setfill('0') << setw(10) << mBufferLength; //temp1 = Integer.parseInt(display.getText().trim(), 16 ); //const int set_buffer_length = 0; //const int set_m_delay = 1; switch (mCmdname) { case set_buffer_length: mCmdIndexString.assign("0000000066#"); break; case set_m_delay: mCmdIndexString.assign("0000000100#"); break; default: mCmdIndexString.assign("0000000066#"); } mCmdIndexString.append(streamIndex.str()); // 00067#00000 (cmdIndex don't care) mCmdIndexString.append("#").append(streamBufferLength.str()); // 00067#00000#00004 mCmdIndexString.append(" > "); // 00067#00000#00004 > tShellbuf.assign("echo ").append(mCmdIndexString).append(fgets(Shellbuf,sizeof(Shellbuf),pp)); system(tShellbuf.c_str()); pclose(pp); ArgArray[0]= mBufferLength; value["CMDINDEX"] = mCmdname; value["Argument"] = ArgArray; value["ReadFileName"] = mFileName; return value; }
unsigned long long dectobin(number){ int q = number/2 , r = number % 2; if (number ==1){ return 1; } else if (q == 1){ return q * 10 + r; } else{ return dectobin(q) * 10 + r; } }
int dectobin(int dec){ if (dec == 0) { return 0; } else { return (dec % 2 + 10 * dectobin(dec / 2)); } }
int main(void) { int ri, looptimes, n; void dectobin(int n); looptimes = GetInteger(); for (ri = 1; ri <= looptimes; ++ri) { n = GetInteger(); dectobin(n); printf("\n"); } return 0; }
int main(void) { int ri,repeat; int i,n; void dectobin(int n); scanf("%d",&repeat); for(ri=1;ri<=repeat;ri++){ scanf("%d",&n); dectobin(n); printf("\n"); } }
// Pre-condition: n is non-negative. // Post-condition: The binary representation of n is printed. void dectobin(int n) { // One digit to print only, so do it. if (n < 2) printf("%d", n); // Solve the problem recursively, print out num/2 in binary, and THEN // print the last digit. else { dectobin(n/2); printf("%d", n%2); } }
int main(void){ unsigned int n, result; printf("-- base10 to binary --\n"); /* para estar completamente correto falta o do..while */ printf("Valor de n:"); scanf("%d", &n); scanf("%*[^\n]"); scanf("%*c"); for (int i = 0; i <= n; i++) { count = 0; result = dectobin(i); printf(" %2d = %10u e custou %3d operações\n", i, result, count); } return 0; }
int main() { // Very basic, NOT comprensive, tests of the recursive methods. int vals[4]; printf("7! = %d\n", fact(7)); printf("31^2 + 32^2 + ... + 200^2 = %d\n", sumsq(31, 200)); vals[0] = 37; vals[1] = 48; vals[2] = 56; vals[3] = 63; printf("vals has %d Odd values.\n", ArrayOdd(vals, 4)); print_reverse("writethisbackwards", 18); printf("\n"); printf("3^10 = %d\n", powerA(3,10)); printf("3^11 = %d\n", powerB(3,11)); if (Rbinary(33, vals, 0, 3) == -1) printf("33 was not found in vals.\n"); dectobin(179); printf("\n"); if (check("madamimadam", 11)) printf("madamimadam is a palindrome.\n"); printf("The 27th Fibonacci number is %d\n", fibonacci(27)); // Test of fast exponentiation vs. regular version int start = time(0); int ans1 = slowModPow(6874, 1000000000, 13713); int end1 = time(0); int ans2 = modPow(6874, 1000000000, 13713); int end2 = time(0); printf("ans1 = %d, ans2 = %d.\n", ans1, ans2); printf("slowModExp took %d sec.\n", end1-start); printf("modPow took %d sec.\n", end2-end1); system("PAUSE"); return 0; }
int main(void) { int ri,repeat; int i,n; void dectobin(int n); scanf("%d",&repeat); for(ri=1;ri<=repeat;ri++){ int k; scanf("%d",&n); k = n < 0 ? 1 : 0; n = n < 0 ? -n : n; if (k) printf("-"); if (n == 0) printf("0"); dectobin(n); printf("\n"); } }
void setlines() { nd2 *q,*current; nd3 *p,*nnode; p=startdict3; q=startcom; int a=1,x=0; char ar[5]; while(q!=NULL&&(strcmp(q->data,"xxxx")!=0)) { strcat(dc,q->data); // printf("%s\n",q->data); q=q->next; } while(q!=NULL) { nnode = (struct dnode3 *)malloc(sizeof(struct dnode3)); strcpy(nnode->data,q->data); x=dectobin(a); sprintf(ar,"%ld",x); strcpy(nnode->bin,ar); nnode->next= NULL; printf("%s\n",nnode->data); if(startdict3==NULL) { startdict3=nnode; current=nnode; } else{ current->next=nnode; current=nnode; } a++; q=q->next; } }
int main(int argc, char *argv[]) { for (int i = 0; i < 50; i++) printf("%6i || %s\n", i, dectobin(i)); return 0; }
void dectobin(int n) { if(n!=0) dectobin(n/2); if(n!=0) printf("%d",n%2); }
void set_reg_val(word *l,int v){ int i; dectobin(l->data,v); }
void compress() { nd *cur=startinp; nd1 *current; int count; int i=0,m=0,x=0,p=0,q=0,j,ml1,ml2; char ar[10]; while(cur!=NULL) { count=0; current=startdict; while(current!=NULL) { if(strcmp(cur->data,current->data)==0) { strcat(str,"00"); strcat(str,current->bin); count=1; goto a; } current=current->next; } current=startdict; while(current!=NULL) { for(i=0;i<32;i++) { if(cur->data[i]==current->data[i]) m++; } if(m==30){ for(i=0;i<32;i++){ if(cur->data[i+1]!=current->data[i+1]&&cur->data[i+2]!=current->data[i+2]) { x=0; strcat(str,"01"); x=dectobin(i+1); sprintf(ar,"%ld",x); strcat(str,ar); strcat(str,current->bin); m++; count=2; goto a; }} //strcat(str,"01"); } //printf("%d\n",m); current=current->next; m=0; } current=startdict; while(current!=NULL) { for(i=0;i<32;i++) { if(cur->data[i]==current->data[i]) m++; } if(m==30){ for(i=0;i<32;i++){ if(cur->data[i]!=current->data[i]) { ml1=i; for(j=i+2;j<32;j++){ if(cur->data[j]!=current->data[j]) ml2=j; } p=0; q=0; strcat(str,"10"); p=dectobin(ml1); sprintf(ar,"%ld",p); if(strlen(ar)==1) { strcat(str,"0000"); } if(strlen(ar)==2) { strcat(str,"000"); } if(strlen(ar)==3) { strcat(str,"00"); } if(strlen(ar)==4) { strcat(str,"0"); } strcat(str,ar); q=dectobin(ml2); sprintf(ar,"%ld",q); if(strlen(ar)==1) { strcat(str,"0000"); } if(strlen(ar)==2) { strcat(str,"000"); } if(strlen(ar)==3) { strcat(str,"00"); } if(strlen(ar)==4) { strcat(str,"0"); } strcat(str,ar); strcat(str,current->bin); m++; count=3; goto a; }} //strcat(str,"01"); } //printf("%d\n",m); current=current->next; m=0; } /*if(m==30){ for(i=0<;i<32;i++){ if(cur->data[i]!=cur->data[i]) } }*/ a: if(count==0) { strcat(str,"11"); strcat(str,cur->data); } //m=0; cur=cur->next; } }