"Detailed" C language: Write a function itob (int n,char s[], int b), convert the integer n to the number in the B binary. Saved to S.

Source: Internet
Author: User

#include <stdio.h>void itob (int n,char s[], int b) {int i=1, for (; i<=32;i++)//32 cycles, guaranteed to get 32 bits of binary {s[i-1]=   n% B; The array starts at number 0 and ends at number 31, n = n/b;  The modulo method is used to get each binary number} for (i=32;i>0;i--) {printf ("%d", s[i-1]).    }}int Main () {char ret[32]; char s[32]; int i=0; int n=0; scanf ("%d", &n); Itob (N,s, 2); At this point the binary b=2 return 0;}

650) this.width=650; "title=" capture. PNG1. PNG "src=" http://s3.51cto.com/wyfs02/M01/74/E8/wKiom1Yt2cSQzk1zAAC7LpY1I-8077.jpg "alt=" Wkiom1yt2csqzk1zaac7lpy1i-8077.jpg "/>

"Detailed" C language: Write a function itob (int n,char s[], int b), convert the integer n to the number in the B binary. Saved to S.

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.