bit pattern

This is a discussion on bit pattern within the C Programming forums, part of the General Programming Boards category; /* the code fragment below is real one...done all by myself..*/ Code: main() { int len,i; char a[]="abcdefg"; len=strlen(a); for(i=0; ...

  1. #1
    Registered User
    Join Date
    Jul 2011
    Posts
    1

    bit pattern

    /* the code fragment below is real one...done all by myself..*/
    Code:
    main()
    {
    int len,i;
    char a[]="abcdefg";
    len=strlen(a);
    for(i=0; i<len; i++)
       printf("%2d ",a[i]);
    }
    the above code outputs decimal values, of the given string as:-(97 98 99..)
    --
    /* this code below is a stolen one */
    Code:
    void bit(int);
    main()
    {
    int val=15;
    printf("bitpattern is:");
    bit(val);
    }
    
    void bit(int n)
    {
    int m,i;
    for(i=15; i>=0; i--)
       {
        m=1<<i;
        if((n&m)==0)
           {
           printf("0");
           }
           else
           {
           printf("1");
           }
        }
    }
    here it gives the bit patterns of a given decimal say 15, as (00001111).
    --

    how do i combine these two functionalities..to get the bit pattern of a given string..?
    thank you..!

  2. #2
    Registered User
    Join Date
    May 2010
    Posts
    2,760
    You may want to start by studying these links: Functions I and Functions II.

    Jim

  3. #3
    Registered User
    Join Date
    Oct 2008
    Location
    TX
    Posts
    2,047
    Please read this forum's homework policy.

  4. #4
    Banned
    Join Date
    Aug 2010
    Location
    Ontario Canada
    Posts
    9,547
    And a pet peeve of mine...

    It's not main()... The minimum skeleton for a proper C program is...
    Code:
    int main (void)
      {
    
        // your code here
      
        return 0; }
    With rare exceptions (such as in microcontroller C) the operating system is expecting the function to be prototyped as int main (void) and it is expecting a return value that is either 0 (for success) or an error code.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. C++ Pattern Help
    By Lestat in forum C++ Programming
    Replies: 10
    Last Post: 10-24-2007, 02:05 PM
  2. what would be an appropriate design pattern?
    By Raven Arkadon in forum C++ Programming
    Replies: 2
    Last Post: 07-14-2006, 07:14 AM
  3. need help printing this pattern
    By Blimpy325 in forum C Programming
    Replies: 4
    Last Post: 03-04-2006, 05:40 AM
  4. (pattern *) pat & pattern * pat
    By siubo in forum C Programming
    Replies: 1
    Last Post: 04-08-2003, 10:03 PM
  5. pattern
    By Unregistered in forum C Programming
    Replies: 16
    Last Post: 05-04-2002, 07:37 PM

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21