Thread: Bit setting

  1. #1
    Registered User
    Join Date
    Mar 2010
    Posts
    94

    Bit setting

    << Split from this 6 year old thread - Bitwise setbits function (knr 2-6) >>

    Please let some one explain me how come:
    n = 8
    p = 16
    are equally shifting the bits for 00???

    But seems it is correct. I am looking forward for the answer as I really need further explanation about this.

    Thanks!

    Quote Originally Posted by olbas View Post
    ok this drove me freakin insane, so i hope i can understand and implement this PITA.

    x ^ (~(~0 << n) << p)
    x = 1234 1234
    n = 8
    p = 16
    ~0 = FFFF FFFF

    Step 1: (~0 << n) = FFFF FF00
    Step 2: ~ = 0000 00FF
    Step 3: << p = 0000 FF00

    Step 4: x ^:
    1234 1234
    0000 FF00
    ---------------
    1234 ED34

    Pleaaaase tell me I got that right.

    The solution included (~(~0U << n), the U represents an unsigned int type, it's not neccessary though is it?

  2. #2
    Registered User
    Join Date
    Mar 2010
    Posts
    94

    Unhappy

    What I am looking for is actually instead with hexadecimal numbers someone to explain with simple binary numbers for example?

    Thanks!

  3. #3
    spurious conceit MK27's Avatar
    Join Date
    Jul 2008
    Location
    segmentation fault
    Posts
    8,300
    Quote Originally Posted by c_lady View Post
    What I am looking for is actually instead with hexadecimal numbers someone to explain with simple binary numbers for example?
    Thanks!
    Your English does not have to be perfect, but it does have to make sense, which that does not make much sense.

    However, you could try here:

    hex numbers
    and
    binary numbers

    If you have some more specific questions that make sense, someone may be willing to help.
    C programming resources:
    GNU C Function and Macro Index -- glibc reference manual
    The C Book -- nice online learner guide
    Current ISO draft standard
    CCAN -- new CPAN like open source library repository
    3 (different) GNU debugger tutorials: #1 -- #2 -- #3
    cpwiki -- our wiki on sourceforge

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. bit value generation doubt
    By roaan in forum C Programming
    Replies: 2
    Last Post: 08-07-2009, 02:23 PM
  2. porting application from 32 bit to 64 bit error
    By gandalf_bar in forum Linux Programming
    Replies: 1
    Last Post: 09-14-2005, 09:20 AM
  3. Bit processing in C
    By eliomancini in forum C Programming
    Replies: 8
    Last Post: 06-07-2005, 10:54 AM
  4. Porting from 32 bit machine to 64 bit machine!
    By anoopks in forum C Programming
    Replies: 10
    Last Post: 02-25-2005, 08:02 PM
  5. Bit Manipulation Questions
    By CPPNewbie in forum C++ Programming
    Replies: 7
    Last Post: 08-12-2003, 02:17 PM