Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > C Programming > Re: How can i compare bit wise?

Reply
Thread Tools

Re: How can i compare bit wise?

 
 
Jack Klein
Guest
Posts: n/a
 
      01-20-2005
On 19 Jan 2005 08:25:53 -0800, "purifier" <(E-Mail Removed)> 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/~a...FAQ-acllc.html
 
Reply With Quote
 
 
 
 
pete
Guest
Posts: n/a
 
      01-20-2005
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
 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Re: How include a large array? Edward A. Falk C Programming 1 04-04-2013 08:07 PM
What is the point of having 16 bit colour if a computer monitor can only display 8 bit colour? How do you edit 16 bit colour when you can only see 8 bit? Scotius Digital Photography 6 07-13-2010 03:33 AM
Re: How can i compare bit wise? purifier C Programming 10 01-20-2005 09:18 PM
64 bit - Windows Liberty 64bit, Windows Limited Edition 64 Bit, Microsoft SQL Server 2000 Developer Edition 64 Bit, IBM DB2 64 bit - new ! vvcd Computer Support 0 09-17-2004 08:15 PM
64 bit - Windows Liberty 64bit, Windows Limited Edition 64 Bit,Microsoft SQL Server 2000 Developer Edition 64 Bit, IBM DB2 64 bit - new! Ionizer Computer Support 1 01-01-2004 07:27 PM



Advertisments