*Sigh*
On Nov 19, 6:24 am, Gaurav Gulzar wrote:
> one liner
> a^=b^=a^=b
>
> On Mon, Nov 19, 2012 at 4:30 PM, abhinav gupta wrote:
>
>
>
>
>
>
>
> > we need to use + and - as operator overloading. so, that i will work f9
> > for ur objects.
>
> > so make operator overloading for + and - opera
one liner
a^=b^=a^=b
On Mon, Nov 19, 2012 at 4:30 PM, abhinav gupta wrote:
> we need to use + and - as operator overloading. so, that i will work f9
> for ur objects.
>
> so make operator overloading for + and - operator.
>
>
> On Sat, Nov 17, 2012 at 9:12 PM, AISHWARYA KUMAR wrote:
>
>
we need to use + and - as operator overloading. so, that i will work f9 for
ur objects.
so make operator overloading for + and - operator.
On Sat, Nov 17, 2012 at 9:12 PM, AISHWARYA KUMAR wrote:
>
> in one line
> a=a^b^(b=a) ;
>
> --
>
>
>
--
*Thanks and Regards,*
Ab
in one line
a=a^b^(b=a) ;
--
That's right!
On Monday, November 5, 2012 2:02:43 AM UTC+5:30, manish wrote:
>
> Swapping two objects (not integers/chars),without using temp...?
> my solution is using xor operation..is that right and ny other solutions ?
--
You received this message because you are subscribed to the Google Gro
Can anyone please help me to understand (with example) that how those
solutions work, if they are OBJECTS?
On Sunday, November 4, 2012 3:32:43 PM UTC-5, manish wrote:
>
> Swapping two objects (not integers/chars),without using temp...?
> my solution is using xor operation..is that right and ny ot
@Don: This can be easily fixed, as there is no need to swap equal values,
so:
void swap(int &a, int &b)
{
if( a != b )
{
a ^= b;
b ^= a;
a ^= b;
}
}
On Monday, November 5, 2012 10:41:42 AM UTC-6, Don wrote:
> Note that most of these methods fail if you try t
Dave is right. The code is undefined, which means that a valid
compiler could produce code which makes monkeys fly out of your nose.
On Nov 13, 12:38 am, Dave wrote:
> @Shivam: Your one-line "solution" violates the sequence point rule. Hence,
> it is non-standard, and the result is compiler depen
But how is that going to work for objects?
On Mon, Nov 5, 2012 at 6:43 AM, Ashok Varma wrote:
> Try this: a = a + b - (b = a); //single line code to swap
>
>
>
>
> On Mon, Nov 5, 2012 at 4:53 AM, Dave wrote:
>
>> @Manish: Sure.
>>
>> a = a + b;
>> b = a - b;
>> a = a - b;
>>
>> In 2-s complemen
Note that most of these methods fail if you try to swap an item with
itself.
For example, swap(a[i], a[j]) will fail if i==j and swap is
implemented as
void swap(int &a, int&b)
{
a ^= b;
b ^= a;
a ^= b;
}
Don
On Nov 4, 3:32 pm, manish wrote:
> Swapping two objects (not integers/chars)
Try this: a = a + b - (b = a); //single line code to swap
On Mon, Nov 5, 2012 at 4:53 AM, Dave wrote:
> @Manish: Sure.
>
> a = a + b;
> b = a - b;
> a = a - b;
>
> In 2-s complement arithmetic, it works even if a + b overflows.
>
> Dave
>
> On Sunday, November 4, 2012 2:32:43 PM UTC-6, manish
@Manish: Sure.
a = a + b;
b = a - b;
a = a - b;
In 2-s complement arithmetic, it works even if a + b overflows.
Dave
On Sunday, November 4, 2012 2:32:43 PM UTC-6, manish wrote:
> Swapping two objects (not integers/chars),without using temp...?
> my solution is using xor operation..is tha
@Coolfrog$: It will be instructive if you do it for yourself. Perhaps
with practice you can work through your confusion. Have you worked out
the bit patterns of those hex constants? They are crucial to
understanding Gene's algorithm. -- Dave
On Nov 22, 6:55 am, "coolfrog$"
wrote:
> @dave
> plz ru
@dave
plz run gene's code for input 0xAD...or send me some link of bitwise
programing which involve simultaneous many opearation... like above...
i am always confused with bitwise programing...
On Sun, Nov 21, 2010 at 11:11 PM, Dave wrote:
> @Coolfrog$: Don't forget the bitwise logical produc
x=((x>>3)&(0x11)|(a<<3)& 0x88 |(a>>1)& 0x44 | (a<<1) && 0x22)
On Sun, Nov 21, 2010 at 11:11 PM, Dave wrote:
> @Coolfrog$: Don't forget the bitwise logical products. What is the bit
> patterns in those hexadecimal constants? Work out the whole example
> and you will see how it works. -- Dave
>
>
@Coolfrog$: Don't forget the bitwise logical products. What is the bit
patterns in those hexadecimal constants? Work out the whole example
and you will see how it works. -- Dave
On Nov 21, 8:21 am, "coolfrog$"
wrote:
> @gene
> plz explain .. what is going on... by taking example. i am unable
@gene
plz explain .. what is going on... by taking example. i am unable to run
a test case
1. x=0xAD (1010 1101)
2. x<<1 ===>01011010
|
x>>1 >01010110
x =0100
how we will get
answer as ( 0101 1011).??
On Sun, Nov 21, 2010 at 9:59 AM, Gene
if the input is in unsigned char x, then
x = ((x << 1) & 0xAA) | ((x >> 1) & 0x55)
x = ((x << 2) & 0xCC) | ((x >> 2) & 0x33)
On Nov 20, 10:41 pm, Divesh Dixit
wrote:
> assuming all are 8bit no.
> input = 0x46 (0100 0110)
> output = 0x26 ( 0010 0110 )
> input = 0x75 (0111 0101)
> output = 0
In C,
unsigned char x;
...
x = (x << 1) | (x >> 1);
x = (x << 2) | (x >> 2);
On Nov 20, 10:41 pm, Divesh Dixit
wrote:
> assuming all are 8bit no.
> input = 0x46 (0100 0110)
> output = 0x26 ( 0010 0110 )
> input = 0x75 (0111 0101)
> output = 0xFC (1110 1010 )
>
> Algorithm..???
--
You re
ohh :(
On 6/23/10, mohit ranjan wrote:
> @Manisha
>
> "swap every two bits"
>
>
> -Mohit
>
>
>
> On Wed, Jun 23, 2010 at 4:56 PM, manisha nandal
> wrote:
>
>> char a=10 01 11 01
>> a = a ^ ~ ( 0 )
>> //now a is 01 10 00 10
>>
>> --
>> You received this message because you are subscribed to the G
@Manisha
"swap every two bits"
-Mohit
On Wed, Jun 23, 2010 at 4:56 PM, manisha nandal
wrote:
> char a=10 01 11 01
> a = a ^ ~ ( 0 )
> //now a is 01 10 00 10
>
> --
> You received this message because you are subscribed to the Google Groups
> "Algorithm Geeks" group.
> To post to this group,
Manisha, this is not the desired result. -- Dave
On Jun 23, 6:26 am, manisha nandal wrote:
> char a=10 01 11 01
> a = a ^ ~ ( 0 )
> //now a is 01 10 00 10
--
You received this message because you are subscribed to the Google Groups
"Algorithm Geeks" group.
To post to this group, send email to
char a=10 01 11 01
a = a ^ ~ ( 0 )
//now a is 01 10 00 10
--
You received this message because you are subscribed to the Google Groups
"Algorithm Geeks" group.
To post to this group, send email to algoge...@googlegroups.com.
To unsubscribe from this group, send email to
algogeeks+unsubscr...@go
Let me explain, supposing that you haven't really tried to understand
the code. The first logical product picks out bits 1, 3, 5, and 7 and
shifts them 1 position to the right. The second logical product picks
out bits 0, 2, 4, and 6 and shifts them 1 position to the left. Then
just or the two sets
@ Dave would u plz bother to discuss how do u arrive at this formula?
On Mon, Jun 21, 2010 at 10:11 PM, Dave wrote:
> Not hard at all:
>
> y = ((x & 0xAA) >> 1) | ((x & 0x55) << 1)
>
> Dave
>
> On Jun 21, 7:07 am, amit wrote:
> > Given a byte, write a code to swap every two bits. [Using bit
> >
oops
so sleek and simple :)
Mohit Ranjan
On Mon, Jun 21, 2010 at 10:11 PM, Dave wrote:
> Not hard at all:
>
> y = ((x & 0xAA) >> 1) | ((x & 0x55) << 1)
>
> Dave
>
> On Jun 21, 7:07 am, amit wrote:
> > Given a byte, write a code to swap every two bits. [Using bit
> > operators] Eg: Input: 10
Not hard at all:
y = ((x & 0xAA) >> 1) | ((x & 0x55) << 1)
Dave
On Jun 21, 7:07 am, amit wrote:
> Given a byte, write a code to swap every two bits. [Using bit
> operators] Eg: Input: 10 01 11 01 Output: 01 10 11 10
--
You received this message because you are subscribed to the Google Groups
a=((number & 01010101)<<1)
b=((number & 10101010)>>1)
a OR b
the bits will be exchanged .
i hope you understood.
On Sat, Sep 5, 2009 at 4:45 AM, Pramod Negi wrote:
> i guess
> num = ((num&0xAA)>>1) | ((num&0x55)<<1))
> will work
>
> Negi
>
>
> On Sat, Sep 5, 2009 at 2:08 PM, Gokul wrote:
>
i guess
num = ((num&0xAA)>>1) | ((num&0x55)<<1))
will work
Negi
On Sat, Sep 5, 2009 at 2:08 PM, Gokul wrote:
>
> how ll u swap every two bits in the a byte??? can anyone help me???
> for eg.
> consider a byte as input...
> 10111010
>
> output should be
> 01110101
>
> it exactly swap the two bit
one linea^=b^=a^=bOn 3/9/06, hemu <[EMAIL PROTECTED]> wrote:
A different way ( or operators) but underlined logic is same as that ofXORA= ( A & ~ B ) | ( ~A & B)B= ( A & ~ B ) | ( ~A & B)A= ( A & ~ B ) | ( ~A & B)
Don't send me any attachment in Micro$oft (.DOC, .PPT)
A different way ( or operators) but underlined logic is same as that of
XOR
A= ( A & ~ B ) | ( ~A & B)
B= ( A & ~ B ) | ( ~A & B)
A= ( A & ~ B ) | ( ~A & B)
--~--~-~--~~~---~--~~
You received this message because you are subscribed to
THat is correct . .On 3/8/06, Dhyanesh <[EMAIL PROTECTED]> wrote:
Although perfectly valid, the first and third are subject to integer overflow. The second one is the safest of all.
On 3/8/06,
[EMAIL PROTECTED] <[EMAIL PROTECTED]> wrote:
-- Manu Jose,mob :09844467453E-mail : [EMAIL PROTECTED]
Although perfectly valid, the first and third are subject to integer overflow. The second one is the safest of all.On 3/8/06,
[EMAIL PROTECTED] <[EMAIL PROTECTED]> wrote:
--~--~-~--~~~---~--~~
You received this message because you are subscribed to the Google Grou
On 3/8/06, [EMAIL PROTECTED] <[EMAIL PROTECTED]> wrote:
>
> I could find only 3
>
> 1) a= a+b;b=a-b;a=a-b;
> 2) a= a^b;b=a^b;a=a^b;
> 3) a= a*b;b=a/b;a=a/b;
>
> Did anyone get the fourth option
Probably this one:
a=a-b; b=a+b; a=b-a;
--~--~-~--~~~---~--~~
You rec
I could find only 3
1) a= a+b;b=a-b;a=a-b;
2) a= a^b;b=a^b;a=a^b;
3) a= a*b;b=a/b;a=a/b;
Did anyone get the fourth option
--~--~-~--~~~---~--~~
You received this message because you are subscribed to the Google Groups
"Algorithm Geeks" group.
To post to this gr
35 matches
Mail list logo