1. This site uses cookies. By continuing to use this site, you are agreeing to our use of cookies. Learn More.

Reading bit and converting to string

Discussion in 'C' started by Jams, Apr 9, 2010.

  1. Jams

    Jams New Member

    Joined:
    Apr 9, 2010
    Messages:
    2
    Likes Received:
    0
    Trophy Points:
    0
    Occupation:
    Student currently on Coop in the Linux Graphics Dr
    Location:
    Barrie,On
    Hi
    I just learned bitshifts and I was wondering whether it is possible to read bits and to convert them into a string.

    Regards
    Jamil
     
  2. xpi0t0s

    xpi0t0s Mentor

    Joined:
    Aug 6, 2004
    Messages:
    3,012
    Likes Received:
    203
    Trophy Points:
    0
    Occupation:
    Senior Support Engineer
    Location:
    England
    Yes it is.
     
  3. Jams

    Jams New Member

    Joined:
    Apr 9, 2010
    Messages:
    2
    Likes Received:
    0
    Trophy Points:
    0
    Occupation:
    Student currently on Coop in the Linux Graphics Dr
    Location:
    Barrie,On
    How would someone go about doing it?
     
  4. Player

    Player New Member

    Joined:
    Aug 3, 2007
    Messages:
    37
    Likes Received:
    0
    Trophy Points:
    0

    This takes 12 in dec, 2 is the base to be used (binary) and is then stored in the str array.

    Code:
    int main(void)
    {
        char str[4];
        printf("12 to binary is %s\n",itoa(12,str,2));
        return(0);
    }
     
    Last edited by a moderator: Apr 16, 2010

Share This Page