Re: If number < 0 return zero else return one
- From: Seebs <usenet-nospam@xxxxxxxxx>
- Date: 14 Sep 2009 18:05:48 GMT
On 2009-09-14, Lakshmi Sreekanth <laki.sreekanth@xxxxxxxxx> wrote:
My problem: I need to return 0 if 'number < 0' other wise return
value
should be 1.
Okay.
Condition: Only by using below operators, We should not use any loops
or if or switch or any thing
Legal ops: ! ~ & ^ | + << >>
Ex: if (number < 0) // But, v should not use "if"
condition.
return 0;
return 1;
Waiting for clue.
Regards,
Laks ..... Sree.....
Sounds like a homework problem.
This is actually moderately hard to do portably; if you're allowed to assume
that you know the target architecture, you may be able to do it by something
as trivial as masking out a sign bit. (But be wary; there probably exists
a machine where there's a -0 integer value, which would trip you up.)
-s
--
Copyright 2009, all wrongs reversed. Peter Seebach / usenet-nospam@xxxxxxxxx
http://www.seebs.net/log/ <-- lawsuits, religion, and funny pictures
http://en.wikipedia.org/wiki/Fair_Game_(Scientology) <-- get educated!
.
- References:
- If number < 0 return zero else return one
- From: Lakshmi Sreekanth
- If number < 0 return zero else return one
- Prev by Date: Re: answer
- Next by Date: Re: integer overflow behavior in other languages
- Previous by thread: Re: If number < 0 return zero else return one
- Next by thread: If number < 0 return zero else return one
- Index(es):
Relevant Pages
|