# how to compare two number sequences

Discussion in 'C++' started by FC, Mar 4, 2005.

1. ### FCGuest

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.

FC, Mar 4, 2005

2. ### David HarmonGuest

On Fri, 04 Mar 2005 00:40:05 -0500 in comp.lang.c++, FC
<> 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

David Harmon, Mar 4, 2005

3. ### FCGuest

David Harmon wrote:
> On Fri, 04 Mar 2005 00:40:05 -0500 in comp.lang.c++, FC
> <> 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.

FC, Mar 4, 2005
4. ### Ioannis VranosGuest

FC wrote:

> David Harmon wrote:
>
>> On Fri, 04 Mar 2005 00:40:05 -0500 in comp.lang.c++, FC
>> <> 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

Ioannis Vranos, Mar 4, 2005