evaluating statements with bitwise operators

This is a discussion on evaluating statements with bitwise operators within the C Programming forums, part of the General Programming Boards category; Hi I wonder how I can find an example when ~n1 + ~n2==~(n1+n2) is true on signed integers. Normally the ...

  1. #1
    Registered User
    Join Date
    Jun 2008
    Posts
    1

    evaluating statements with bitwise operators

    Hi

    I wonder how I can find an example when ~n1 + ~n2==~(n1+n2) is true on signed integers. Normally the value of this expression is 0 but is it always? Is there a simple way to find a solution without running a code with loop that tests on range of numbers?

    Another question:

    lets define u2 as casted unsigned number of n2, same with u1 of n1

    is this (int) (u1-u2) always equal to expression -(n2-n1)? Int before (u1-u2) means that substraction is done and the result is casted to a signed integer.

    and what this means?

    (n>>24) | ((n<<8) & 0x00FF0000)?

    Thanks for any input!
    Last edited by tbabula; 06-25-2008 at 12:59 PM.

  2. #2
    and the Hat of Guessing tabstop's Avatar
    Join Date
    Nov 2007
    Posts
    14,185
    ~n1 + ~n1 == ~(n1+n2) should be solvable for n2, once you picked an n1. Unless that second n1 was supposed to be an n2. Otherwise it might help to remember that ~n1 = -n1 (in one's complement) or ~n1 = -n1-1 (in two's complement).

    For the third, | means or, so any bit that's "on" in either the left side or the right side will be "on" in the result. << is left shift, so all bits are moved over eight spots (the eight bits on the left to start with are gone), and zeroes are filled on from the right. >> means right shift; if n is negative, it is up to the implementation whether the sign bit is filled in from the right, or if zeroes are filled in.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Bitwise operators
    By gnewfenix in forum C Programming
    Replies: 2
    Last Post: 05-16-2009, 08:43 PM
  2. Bitwise Operators
    By rrc55 in forum C Programming
    Replies: 6
    Last Post: 04-30-2009, 11:37 AM
  3. Palindromes and Bitwise operators
    By Dr Tornillo in forum C Programming
    Replies: 8
    Last Post: 08-02-2007, 02:31 PM
  4. bitwise and arithmetic Operators
    By Whiteghost in forum C Programming
    Replies: 4
    Last Post: 12-28-2006, 01:13 PM
  5. Bitwise operators. What's this????????
    By money? in forum C Programming
    Replies: 20
    Last Post: 06-17-2003, 06:03 PM

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