Enter a decimal positive integer smaller than 256 on the keyboard, and convert the number to an octal binary number.

Source: Internet
Author: User
# Include <stdio. h>
# Include <conio. h>
Void main ()
{
Int num;
Int B0, B1, B2, B3, B4, B5, B6, B7;
Printf ("Please input a integer number :");
Scanf ("% d", & num );
B0 = num % 2;
B1 = num/2% 2;
B2 = num/4% 2;
B3 = num/8% 2;
B4 = num/16% 2;
B5 = num/32% 2;
B6 = num/64% 2;
B7 = num/128% 2;
Printf ("% d's binary is: % 1D % 1D % 1D % 1D % 1D % 1D % 1D % 1D % 1D \ n", num, B7, B6, B5, B4, b3, B2, B1, B0 );
Getch ();
}


# Include <stdio. h>
# Include <conio. h>
# Include <math. h>
Void main ()
{
Int num, N, I, B [8];
Printf ("Please input a integer number :");
Scanf ("% d", & num );
For (I = 1; I <8; I ++)
{
N = POW (2, I);/** // * The POW passes debugging in BC/TC. The system automatically forces the conversion, but an error occurs in VC, the parameter must be double or float */
B [I] = (Num/n) % 2;
}
For (I = 7; I> = 0; I --)
Printf ("% d", B [I]);
Getch ();
}

# Include <stdio. h>
# Include <conio. h>
Void main ()
{
Int m, n = 2, I = 0, J, a [8];
Printf ("Please input a integer number (M> = 0 and M <= 255 ):");
Scanf ("% d", & M );
While (M <0 & amp; M & gt; 255)
{
Printf ("Please input a number (M> = 0 and M <= 255 ):");
Scanf ("% d", & M );
}
While (M! = 0)
{
A [I] = m % 2;
I ++;
M = m/2;
}
For (j = 0; j <8-I; j ++)
Printf ("0 ");
For (j = I-1; j> = 0; j --)
Printf ("% d", a [J]);
Getch ();
}

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.