Thread: who can help me ???!!!!

  1. #1
    Registered User
    Join Date
    Jun 2006
    Posts
    8

    who can help me ???!!!!

    i want to reverse the bits of unsigned number by using bitwise operatores ( & , | , ^ , ~ , << , >> ) , i am working in borland C++

    example :
    00110101 -> 10101100

    please help me if u can .....


  2. #2
    C++ Witch laserlight's Avatar
    Join Date
    Oct 2003
    Location
    Singapore
    Posts
    28,413
    What have you tried so far?
    Quote Originally Posted by Bjarne Stroustrup (2000-10-14)
    I get maybe two dozen requests for help with some sort of programming or design problem every day. Most have more sense than to send me hundreds of lines of code. If they do, I ask them to find the smallest example that exhibits the problem and send me that. Mostly, they then find the error themselves. "Finding the smallest program that demonstrates the error" is a powerful debugging tool.
    Look up a C++ Reference and learn How To Ask Questions The Smart Way

  3. #3
    Registered User
    Join Date
    Jun 2006
    Posts
    8
    ?????

  4. #4
    Lurking whiteflags's Avatar
    Join Date
    Apr 2006
    Location
    United States
    Posts
    9,613
    Use exclusive or.

  5. #5
    Registered User
    Join Date
    Jun 2006
    Posts
    8
    thanks citizen ,,,

    but i must use ^ with what ????

  6. #6
    (?<!re)tired Mario F.'s Avatar
    Join Date
    May 2006
    Location
    Ireland
    Posts
    8,446
    what have you tried so far?
    Originally Posted by brewbuck:
    Reimplementing a large system in another language to get a 25% performance boost is nonsense. It would be cheaper to just get a computer which is 25% faster.

  7. #7
    Registered User
    Join Date
    Aug 2005
    Location
    Austria
    Posts
    1,990
    Quote Originally Posted by backtolife
    thanks citizen ,,,

    but i must use ^ with what ????
    xor doesn't help much for reversing. it's better used for inverting.
    Kurt

  8. #8
    Registered User
    Join Date
    Dec 2003
    Posts
    167
    http://www.jjj.de/fxt/fxtbook.pdf

    Have a look at the bit wizardry chapter.
    silk.odyssey

  9. #9
    Just Lurking Dave_Sinkula's Avatar
    Join Date
    Oct 2002
    Posts
    5,005
    Quote Originally Posted by backtolife
    please help me if u can .....
    Announcement: Homework

    Post the code of your initial attempt and better help will follow.

    [edit]Or cheat by searching for "reverse bits".
    7. It is easier to write an incorrect program than understand a correct one.
    40. There are two ways to write error-free programs; only the third one works.*

  10. #10
    C++ Witch laserlight's Avatar
    Join Date
    Oct 2003
    Location
    Singapore
    Posts
    28,413
    Use exclusive or.
    I would use &, |, << and >>, or perhaps their assignment variants.
    Quote Originally Posted by Bjarne Stroustrup (2000-10-14)
    I get maybe two dozen requests for help with some sort of programming or design problem every day. Most have more sense than to send me hundreds of lines of code. If they do, I ask them to find the smallest example that exhibits the problem and send me that. Mostly, they then find the error themselves. "Finding the smallest program that demonstrates the error" is a powerful debugging tool.
    Look up a C++ Reference and learn How To Ask Questions The Smart Way

  11. #11
    and the hat of int overfl Salem's Avatar
    Join Date
    Aug 2001
    Location
    The edge of the known universe
    Posts
    39,660
    > please help me if u can .....
    Start by showing us a program which uses & and >> in a for loop to print each bit in turn.

    If you then use << on that bit, you might be onto something.
    If you dance barefoot on the broken glass of undefined behaviour, you've got to expect the occasional cut.
    If at first you don't succeed, try writing your phone number on the exam paper.

Popular pages Recent additions subscribe to a feed