Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > comp.lang.c > #142867 > unrolled thread
| Started by | Mateusz Viste <mateusz@wont.tell> |
|---|---|
| First post | 2019-04-06 18:22 +0000 |
| Last post | 2019-04-06 23:52 -0700 |
| Articles | 3 — 3 participants |
Back to article view | Back to comp.lang.c
This discussion starts older than the indexed window; earlier articles aren't shown. The article labeled Started by
below is the oldest one visible, not the original post.
Re: Application Exercises Mateusz Viste <mateusz@wont.tell> - 2019-04-06 18:22 +0000
Re: Application Exercises donalhambra@gmail.com - 2019-04-06 12:07 -0700
Re: Application Exercises Tim Rentsch <tr.17687@z991.linuxsc.com> - 2019-04-06 23:52 -0700
| From | Mateusz Viste <mateusz@wont.tell> |
|---|---|
| Date | 2019-04-06 18:22 +0000 |
| Subject | Re: Application Exercises |
| Message-ID | <5ca8ee5c$0$21621$426a34cc@news.free.fr> |
On Sat, 06 Apr 2019 18:01:32 +0000, Stefan Ram wrote:
> |Write a function to detect whether two integral numbers are |equal
> without using any comparison operators.
>
> . As a hint he wrote: "Think of bit operators.".
/* returns 0 if a == b, non-zero otherwise */
int isnotequal(int a, int b) {
return(a ^ b);
}
Mateusz
[toc] | [next] | [standalone]
| From | donalhambra@gmail.com |
|---|---|
| Date | 2019-04-06 12:07 -0700 |
| Message-ID | <45fd06c1-e9b3-496a-b3f1-13c2c191c42a@googlegroups.com> |
| In reply to | #142867 |
On Saturday, April 6, 2019 at 2:22:27 PM UTC-4, Mateusz Viste wrote:
> On Sat, 06 Apr 2019 18:01:32 +0000, Stefan Ram wrote:
> > |Write a function to detect whether two integral numbers are |equal
> > without using any comparison operators.
> >
> > . As a hint he wrote: "Think of bit operators.".
>
> /* returns 0 if a == b, non-zero otherwise */
> int isnotequal(int a, int b) {
> return(a ^ b);
> }
With signed magnitude -1 ^ +1 gives "minus zero" even
though -1 != +1.
-Don
[toc] | [prev] | [next] | [standalone]
| From | Tim Rentsch <tr.17687@z991.linuxsc.com> |
|---|---|
| Date | 2019-04-06 23:52 -0700 |
| Message-ID | <865zrqmhmq.fsf@mailhub.linuxsc.com> |
| In reply to | #142867 |
ram@zedat.fu-berlin.de (Stefan Ram) writes:
> Mateusz Viste <mateusz@wont.tell> writes:
>
>> On Sat, 06 Apr 2019 18:01:32 +0000, Stefan Ram wrote:
>>
>>> |Write a function to detect whether two integral numbers are |equal
>>> without using any comparison operators.
>>> . As a hint he wrote: "Think of bit operators.".
>>
>> /* returns 0 if a == b, non-zero otherwise */
>> int isnotequal(int a, int b) {
>> return(a ^ b);
>> }
>
> Yeah, but what about padding bits (N2310, 6.2.6.2p5)?
Padding bits do not participate in the computation of
the &, ^, and | operators. Unless the result is a trap
representation corresponding to a negative zero, or
the (trap) distinguished representation for two's
complement, these operators work as expected and always
produce valid values.
[toc] | [prev] | [standalone]
Back to top | Article view | comp.lang.c
csiph-web