-
December 12th, 2003, 05:01 AM
#1
Comparison
Hi Gurus,
Its somewhat frustrating question.
Is there any way to compare two numbers without using any conditional operator like (<,>) ?
thanx,
-piyu
-
December 12th, 2003, 05:18 AM
#2
why cant you use the '<','>', etc. operators ?
your humble savant
-
December 12th, 2003, 05:18 AM
#3
What do you mean under "to compare two numbers" ?
-
December 12th, 2003, 06:32 AM
#4
See,
Suppose a = 10 and b = 20. are two numbers.
i want to know which is greater out of them. For this purpose we can use '<','>' operators. but i don't want to use them to achieve the result as 20.
Is there any way out ?
-
December 12th, 2003, 06:37 AM
#5
You dont want to use:
PHP Code:
int a = 10 ;
int b = 20 ;
if(a>b)
{
// do something
}
if(b>a)
{
// do something
}
if(20==b)
{
// do something
}
?
your humble savant
-
December 12th, 2003, 06:39 AM
#6
Yah, inequality operators are terrible for determining order.
I mean what does one have to do with the other.
Wakeup in the morning and kick the day in the teeth!! Or something like that.
"i don't want to write leak free code or most efficient code, like others traditional (so called expert) coders do."
-
December 12th, 2003, 06:43 AM
#7
yes, TheRogue
I really don't want to use these operators.
I am also thinking that we can' t do this.. but still i wan't to raise on CODEGURU coz there are really good ppls who can answer it well.
-Piyu
-
December 12th, 2003, 06:47 AM
#8
Well, I am just curious. Please tell us why you don't want to use
them.
Wakeup in the morning and kick the day in the teeth!! Or something like that.
"i don't want to write leak free code or most efficient code, like others traditional (so called expert) coders do."
-
December 12th, 2003, 06:52 AM
#9
Pretty please..with sugar on top.
Wakeup in the morning and kick the day in the teeth!! Or something like that.
"i don't want to write leak free code or most efficient code, like others traditional (so called expert) coders do."
-
December 12th, 2003, 06:52 AM
#10
Hi souldog,
Thanx for being curios with the question.
See.
I want to write an assembly language code for one specific microprocessor which doesn't contain any cmp ('compare' ), jl('jump if less'), jg (jump if greater) instructions. so i am thinking how it is possible to find greatest number out of A and B.
May be my approach is wrong. isn't it ?
please suggest.
-Piyu
-
December 12th, 2003, 06:56 AM
#11
If it has a check for zero,
could you decrement both variables until one of them is zero ?
your humble savant
-
December 12th, 2003, 07:02 AM
#12
Well if you can look at the bits in the numbers starting with
the MSB and find the first place they are different, then the number
that has a 1 in this bit is larger.
Wakeup in the morning and kick the day in the teeth!! Or something like that.
"i don't want to write leak free code or most efficient code, like others traditional (so called expert) coders do."
-
December 12th, 2003, 07:08 AM
#13
hi TheRogue
---------------
If it has a check for zero,
could you decrement both variables until one of them is zero ?
----------------
Fortunatly, i have that instruction with me.
I can able to decrement both variable until one of them is ZERO.
now please clarify..
regards,
-Piyu
-
December 12th, 2003, 07:12 AM
#14
start:
decrement both variables
if neither variable has reached zero, goto start:
if one variable has reached zero it is smaller
if both variables have reached zero they are the same
ps. what is the microprocessor ?
your humble savant
-
December 12th, 2003, 07:13 AM
#15
Do you have a carry flag in a FLAGS register. You can subtract the two numbers and see if a borrow was needed.
Wakeup in the morning and kick the day in the teeth!! Or something like that.
"i don't want to write leak free code or most efficient code, like others traditional (so called expert) coders do."
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|