Huawei Machine Test-numeric conversion on 32-bit processors

Source: Internet
Author: User

On a 32-bit processor, convert any integer to a binary form.

Required implementation functions:

void Dectobin(unsignedintIDec,Char Pbin[ +])


Input: IDec decimal integer to convert

Output: Pbin converted to binary string, high on left, less than 32 bit 0


Example

Input: 123

Output: {"00000000000000000000000001111011"}  


#include <stdio.h>void dectobin (unsigned int iDec, char pbin[32]) {    int i,a[32],j=0;    for (i = 0; i <; i++)        pbin[i] = ' 0 ';    while (idec>0) {a[j++]=idec%2;idec/=2;} int k=j-1;for (i=32-j;i<32;i++) pbin[i]=a[k--]+ ' 0 ';} int main () {        unsigned int idec;    Char Pbin[32];while (~scanf ("%d", &idec)) {    Dectobin (Idec, pbin);    for (int i = 0; i < i++) printf ("%c", Pbin[i]);p rintf ("\ n");}        




Huawei Machine Test-numeric conversion on 32-bit processors

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.