Re: How can i compare bit wise?

Discussion in 'C Programming' started by Jack Klein, Jan 20, 2005.

  1. Jack Klein

    Jack Klein Guest

    On 19 Jan 2005 08:25:53 -0800, "purifier" <> wrote
    in comp.lang.c:

    > Hi everyone,
    > I thought of writing a program which finds the greater of two numbers..
    > of course with a small condition... without using "if" and conditional
    > operators... I got an idea on how to implement the program... I have an
    > alternative too... that is to use bitwise comparison in the folowing
    > manner:


    Bit-wise is either poorly defined or undefined for signed integer
    types, and useless for floating point types.

    #include <stdio.h>
    #include <limits.h>

    int compare(int i1, int i2)
    {
    return (i1 >= i2) * i1 + (i1 < i2) * i2;
    }

    int main(void)
    {
    printf("greater of %d and %d is %d\n",
    6, 12, compare(6, 12));
    printf("greater of %d and %d is %d\n",
    INT_MAX, INT_MIN, compare(INT_MAX, INT_MIN));
    return 0;
    }


    --
    Jack Klein
    Home: http://JK-Technology.Com
    FAQs for
    comp.lang.c http://www.eskimo.com/~scs/C-faq/top.html
    comp.lang.c++ http://www.parashift.com/c -faq-lite/
    alt.comp.lang.learn.c-c++
    http://www.contrib.andrew.cmu.edu/~ajo/docs/FAQ-acllc.html
     
    Jack Klein, Jan 20, 2005
    #1
    1. Advertising

  2. Jack Klein

    pete Guest

    Jack Klein wrote:

    > Bit-wise is either poorly defined or undefined for signed integer
    > types, and useless for floating point types.


    Undefined for floating point types.

    --
    pete
     
    pete, Jan 20, 2005
    #2
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. mrinalroy

    Bit wise shift operators

    mrinalroy, Oct 20, 2006, in forum: Java
    Replies:
    3
    Views:
    453
    IchBin
    Oct 20, 2006
  2. purifier

    Re: How can i compare bit wise?

    purifier, Jan 19, 2005, in forum: C Programming
    Replies:
    10
    Views:
    531
    Default User
    Jan 20, 2005
  3. s.subbarayan
    Replies:
    4
    Views:
    374
    s.subbarayan
    Apr 7, 2005
  4. Enrique Cruiz

    Row-wise vs. column-wise image processing

    Enrique Cruiz, Jan 25, 2007, in forum: C Programming
    Replies:
    10
    Views:
    738
    christian.bau
    Jan 26, 2007
  5. Enrique Cruiz
    Replies:
    5
    Views:
    455
    Jim Langston
    Jan 25, 2007
Loading...

Share This Page