Search:

Type: Posts; User: oogabooga

Search: Search took 0.03 seconds.

  1. Replies
    33
    Views
    15,763

    I was able to remove the local variable from my...

    I was able to remove the local variable from my solution. So it's possible with no locals or casting and without + (or -, which is not allowed anyway).

    But it's pretty unintelligible and has taken...
  2. Replies
    33
    Views
    15,763

    Here's a hint for anyone interested in trying...

    Here's a hint for anyone interested in trying this.

    To find the answer, you only have to compare 1 bit -- the highest order bit where the two numbers differ.

    So the first trick is to create a...
  3. Replies
    33
    Views
    15,763

    Excellent. Thanks. Here's a rewrite. The overall...

    Excellent. Thanks. Here's a rewrite. The overall alg still seems to work.


    // Logical Right-Shift
    int lrs(int x, int n) {
    if (x < 0) {
    x = (x >> 1) & INT_MAX;
    n--;
    }...
  4. Replies
    33
    Views
    15,763

    If you've bothered to read the thread you'll know...

    If you've bothered to read the thread you'll know that there are a lot of other cases for which your attempt fails.

    I've solved it using just ! ~ & ^ | >>
    It assumes 2's complement but it works...
  5. Replies
    33
    Views
    15,763

    isitGreater(INT_MAX-1, INT_MIN+1) is another...

    isitGreater(INT_MAX-1, INT_MIN+1) is another example that doesn't work. There are many similar examples.

    whiteflag's suggestion (casting to a larger type, which I assume you can't do) gave me an...
  6. Replies
    33
    Views
    15,763

    Take x is -4, y is 5 Where's the overflow? It...

    Take x is -4, y is 5
    Where's the overflow?
    It seems to give the correct answer 0.

    Your second example (-2147483648) is INT_MIN, which I pointed out won't work since you can't take the 2's...
  7. Replies
    33
    Views
    15,763

    Obviously it'll fail if x is INT_MIN, but...

    Obviously it'll fail if x is INT_MIN, but otherwise it seems okay.
    Give some specific values for which it fails.
Results 1 to 7 of 7