Results 1 to 6 of 6

Thread: C program to find the binary form of given character

  1. #1
    Join Date
    Dec 2009
    Posts
    59

    C program to find the binary form of given character

    Hello Guys,

    I have to write one C program. In which the program should display the binary form of given inputted character. The character should be provided by the user. I have one code for this, but when I run this code it displays garbage value. I am not able to find out the cause behind this. If you have any C program code find the binary form of given character, then please let me aware about that. I would appreciate your help.

  2. #2
    Join Date
    Feb 2008
    Posts
    1,852

    Re: C program to find the binary form of given character

    Hi friend,

    Please refer following C program code to find the binary form of given character. To find out binary value of given character I have used the 'while' loop in program. The condition checking done in the 'While' loop. See below:
    main()
    {
    unsigned char a1;
    unsigned char mask1 = 0x80;

    puts("Enter single character");
    scanf("%c",&a1);
    puts("binary equvalent of number is ");
    while(mask1)
    {
    (a1 & mask1)? printf("1"):printf("0");
    mask >>= 1;
    }
    getch();
    }

  3. #3
    Join Date
    Jan 2008
    Posts
    1,521

    Re: C program to find the binary form of given character

    See the below example to print the binary form of given character:
    int main()
    {
    int lBinaryValue2=0;
    char chInputChar2;
    printf("Enter a character");
    scanf(" c" &chInputChar2);
    lBinaryValue ConvertDecimalToBinary((int)chInputChar2);
    printf(" d" lBinaryValue2);
    return 0;

    }
    int ConvertDecimalToBinary2(int lInput2)
    {
    int lTempInt lInput2;
    int lBinaryOutput2=0;
    int i 0;
    while(lTempInt2 > 0)
    {
    lBinaryOutput2=lBinaryOutput2 +(lTempInt2)*((int)pow(10 i++));
    lTempInt2=lTempInt2/2;
    }
    return lBinaryOutput2;
    }

  4. #4
    Join Date
    Apr 2008
    Posts
    1,948

    Re: C program to find the binary form of given character

    Hi,

    It very difficult to code C code to print the binary value of given character. First you need to accept the character from the user. Then you need to implement the C program logic to evaluate the equivalent binary value for that character. See below code:
    #include<conio.h>
    #include<stdio.h>

    void main()
    {
    char chm;
    int im km dm 1 summ 0;
    printf("enter the chracter");
    scanf(" c" &chm);
    im=chm;

    while(im> 1)
    {

    km=im/2;
    summ summ+km*d;
    im im/2;
    dm dm*10;

    }
    printf(" binary is d" summ);
    getch();
    }

  5. #5
    Join Date
    May 2008
    Posts
    2,012

    Re: C program to find the binary form of given character

    To find the binary value of any inputted character you should use the following function in you C program code. When you accept the value from the user then you should call the following function. This function comprises the code to print the binary value of given number. I suggest you to try this function first and let me know it it is useful for you or not.
    void funBn(int numB)
    {
    int remB;
    if(numB=0) return;

    remB= numB/2;

    funB(numB/2);

    printf(" %d" remB);
    }

  6. #6
    Join Date
    Apr 2008
    Posts
    2,005

    Re: C program to find the binary form of given character

    Hi friend,

    It's very simple to find out binary form of any given character. If you looping concept is clear then I don't think that you will get more difficulties to code binary value program. You need to use the use while loo to achieve this task. I have code the similar program using the while loop. You can also find out the binary value using the 'if' loop also. If you are going to use the while loop then you can refer below some code:
    while(chr1> 1)
    {
    Kr= ir/2;

    tem= tem+kr*dr;
    ir= ir/2;
    dr=dr*10;

    }

Similar Threads

  1. Need C program to print triangle of character or number
    By Khan Baba in forum Software Development
    Replies: 5
    Last Post: 17-09-2011, 04:40 PM
  2. c program to convert decimal to binary
    By Oswaldo in forum Software Development
    Replies: 3
    Last Post: 25-11-2009, 03:45 PM
  3. How to find Character map on mac pc?
    By Neel21 in forum Operating Systems
    Replies: 3
    Last Post: 16-10-2009, 04:12 AM
  4. Program to Convert Hexadecimal No into Binary No in C language
    By Joyjeet in forum Software Development
    Replies: 4
    Last Post: 06-03-2009, 01:12 PM
  5. How to find the 8-character DOS name for a folder?
    By Saphire in forum Window 2000 Help
    Replies: 1
    Last Post: 03-05-2007, 09:00 PM

Tags for this Thread

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Page generated in 1,713,550,304.99415 seconds with 17 queries