Thread: Reverse of a Binary

Threaded View

Previous Post Previous Post   Next Post Next Post
  1. #1
    Registered User
    Join Date
    Oct 2002
    Posts
    6

    Unhappy Reverse of a Binary

    Can anyone help and let me know how can I reverse a Binary number, please ASAP.
    What I mean is if I get 00000001 00000010 00000010 I should get as a result: 10000000 01000000 01000000.
    void reverse_bit(unsigned char x, char *pt)
    {
    int t, i;
    unsigned char hold;
    char temp[8];
    char tmp_bin[8];
    char *pt2=0;

    tmp_bin[0]='\0';
    pt2 = tmp_bin;
    display_binary(x, pt2);


    hold = x;

    for(t=1; t <count; t++)
    {
    if(hold & HIGH_BIT)
    hold = ( hold << 1 | 1);
    else
    hold = hold << 1;
    display_binary(hold, pt2);
    }
    x = hold;
    strcpy(temp,"");
    for(i = HIGH_BIT; i > 0; i = i/2)
    { if(x & i)
    sprintf(temp, "%s1", temp);
    else
    sprintf(temp, "%s0", temp);
    }

    strcpy(pt,temp);}
    this is what i did and it does not work.
    Last edited by xeneize; 10-07-2002 at 12:30 PM.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Replies: 0
    Last Post: 11-04-2006, 11:07 AM
  2. gethostbyaddr() reverse lookups failing (???)
    By Uncle Rico in forum C Programming
    Replies: 9
    Last Post: 08-19-2005, 09:22 AM
  3. Binary Search Trees Part III
    By Prelude in forum A Brief History of Cprogramming.com
    Replies: 16
    Last Post: 10-02-2004, 03:00 PM
  4. Tutorial review
    By Prelude in forum A Brief History of Cprogramming.com
    Replies: 11
    Last Post: 03-22-2004, 09:40 PM
  5. Request for comments
    By Prelude in forum A Brief History of Cprogramming.com
    Replies: 15
    Last Post: 01-02-2004, 10:33 AM