Velocity Reviews > C++ > how to compare two number sequences

# how to compare two number sequences

FC
Guest
Posts: n/a

 03-04-2005
Hi all:
I have two 32 bit long sequence of binary random numbers. When I compare
them side by side I want to count all the transitions from one to zero,
and all the transitions from zero to one between the two sequences like
this:

01100110101010011010101010011001
00110110111001100101010111010101
v ^ ^ v^^vv^v^v^v^ ^ v^

Where v is when it goes low from the first to the second sequence and ^
when it goes high.

So far I have implemented an xor and I can count all the transitions but
I cannot tell them apart (between high and low). Is there a function or
a method that will allow me to tell them apart? If I could do this in
one pass will be even better. Thanks in advance.

David Harmon
Guest
Posts: n/a

 03-04-2005
On Fri, 04 Mar 2005 00:40:05 -0500 in comp.lang.c++, FC
<(E-Mail Removed)> wrote,
>I have two 32 bit long sequence of binary random numbers. When I compare
>them side by side I want to count all the transitions from one to zero,
>and all the transitions from zero to one

A & ~B
B & ~A

FC
Guest
Posts: n/a

 03-04-2005
David Harmon wrote:
> On Fri, 04 Mar 2005 00:40:05 -0500 in comp.lang.c++, FC
> <(E-Mail Removed)> wrote,
>
>>I have two 32 bit long sequence of binary random numbers. When I compare
>>them side by side I want to count all the transitions from one to zero,
>>and all the transitions from zero to one

>
>
> A & ~B
> B & ~A
>

Thanks, that was painless.

Ioannis Vranos
Guest
Posts: n/a

 03-04-2005
FC wrote:

> David Harmon wrote:
>
>> On Fri, 04 Mar 2005 00:40:05 -0500 in comp.lang.c++, FC
>> <(E-Mail Removed)> wrote,
>>
>>> I have two 32 bit long sequence of binary random numbers. When I
>>> compare them side by side I want to count all the transitions from
>>> one to zero, and all the transitions from zero to one

>>
>>
>>
>> A & ~B
>> B & ~A
>>

> Thanks, that was painless.

You can also use std::bitset.

--
Ioannis Vranos

http://www23.brinkster.com/noicys