How to convert decimal to binary in C language???

Updated on technology 2024-02-09
9 answers
  1. Anonymous users2024-02-05

    I've written a simple one for your reference before because it's not very perfect with include

    #include

    #include

    #include

    using namespace std;

    int main()

    string a="";The binary number to be converted.

    double num=0;

    char* p='.');Position the pointer p to the decimal point.

    char* pp=p-1;Position the pointer pp at the last position of the integer part.

    for(int i=0;pp!=;i++,pp--)if(*pp=='1') num+=pow(2,i);Calculate the integer part.

    pp=p+1;

    for(i=-1;pp!=;i--,pp++)if(*pp=='1') num+=pow(2,i);Calculate the decimal part.

    cout<

    else count++;

    while(count!=7);Calculate the decimal part.

    cout<

  2. Anonymous users2024-02-04

    Binary to decimal.

    Method: "Sum by weight".

    Example: Rule: The number of digits in the single digit is 0, and the number of digits in the tens digit is 1,..Ascend in turn, and ten.

    The number of quantiles is -1, and the number of times of numbers in the percentile is -2,..Descending order.

    Note: Not any decimal number can be converted to a binary number with finite digits.

    2) Decimal to binary.

    Decimal integer to binary number: "divide by 2 to take the remainder, in reverse order" (divide by 2 to take the remainder) Example]:

    44÷2 ……It is 0

  3. Anonymous users2024-02-03

    Decimal numbers, individual digits, respectively: .Thousand, hundred, ten, one .

    Binary numbers, each bit of the hidden blue rise, respectively: .Eight, four, two, one...

    The rest is up to you, and it's slow to explore.

    The decimal number, the old 8031, is: 8 thousand, 0 hundred, 3 ten, 1.

    The binary number, 1101, is: 1 eight, 1 four, 0 two, 1 one, i.e. 13 in decimal.

  4. Anonymous users2024-02-02

    Decimal is converted to binary (formula: divide r and reverse remainder).

    For example: 30d=()b

    Use the decimal number 30 divided by the decimal number 2 to convert to the base number as follows: the high digit is 0 so it is 30d = (11110) b hope it helps you o.

    --Satisfied with the adoption of the Austrian ---

  5. Anonymous users2024-02-01

    Carry system

    The decimal system is every decimal oneThe decimal system is the notation we use on a daily basis.

    I used itTen numbers. The same number represents different values in different digits of the number, which is called the place-value system (place-value principle).

    Such as:, 2 on the thousand digit denotes, 2 in the single digit is depresented

    Binary system is every two into one

  6. Anonymous users2024-01-31

    Computer conversion of decimal and binary.

  7. Anonymous users2024-01-30

    Act I: C Procedure.

    #include""

    int main()

    for(int j=i; j>=0; j--)printf("%d",a[j]);

    return 0;

    Method 2: JS converts decimal numbers into binary numbers.

  8. Anonymous users2024-01-29

    This question is very basic, first give you the idea, and then tell you **.

    First, enter a string. Since the general integer int type is 4 bytes, 32 bits. Therefore, the required input string cannot exceed 32 bits, and if it is exceeded, it will not be displayed in the program.

    Second, to determine the length of the string (which can be strlen() or in some other way, add the length of the string to i.

    It is determined from the first digit of the string, if the j-digit of the character is"1"then add a 2 to the i-j power. For example, 0101 has a character length of 4 and the second digit is"1"then add 2 to the power (4-2) = 4, and the fourth digit is"1", then add 2 to the power (4-4) = 1In the end, it adds up to 4+1=5

    Actually, only a part of it is provided here, and the first place to consider is the real complete binary to decimal system"0"Still"1"To determine that the decimal system is exactly negative. First give binary to decimal without considering negative numbers**:

    #include

    #include

    #include

    int binary_to_decimal(const char a)

    i--;Determine the length of the string.

    if(i>32) error occurs when the maximum range of 32-bit integers is exceeded.

    elsefor(int j=i;j>0;j--)

    return sum;

    void main()

  9. Anonymous users2024-01-28

    Method: Multiply each number of binary defaults by the corresponding power of 2 from right to left, and from left to right after the decimal point.

    For example, binary numbers are converted to decimal numbers.

    binary) = 1 * 2 0 + 0 * 2 1 + 1 * 2 2 + 1 * 2 3 + 0 * 2 -1 + 1 * 2 -2 = 1 + 0 + 4 + 8 + 0 + decimal).

    So to sum up, the general formula is:

    .EFG (binary) = d*2 0 + c*2 1 + b*2 2 + a*2 3 + e*2 -1 + f*2 -2 + g*2 -3 (decimal).

Related questions
7 answers2024-02-09

First convert to binary (except 16 remainder), then convert binary to decimal.

15 answers2024-02-09

include: This header file declares the basic services required for all IO operations, i.e., the input and output operations that support the stream, e.g. cin and cout in the program >>>More