Searching \ for ' [PIC] tiny challenge ;)' in subject line. ()
Help us get a faster server
FAQ page: piclist.com/techref/microchip/devices.htm?key=pic
Search entire site for: 'tiny challenge ;)'.

No exact or substring matches. trying for part
'[PICLIST] [PIC] tiny challenge ;)'
2000\08\10@171925 by

Hi guys. ;)

I got free minute and decided to drop this message. Anyone who
wants to refresh brain from coding and solve a small puzzle are
invited ;)

Well.

We have number in W register in 00ab00cd view, where 0's are
actually zeroes and abcd are some bits we are playing with.

The challenge is to convert 00ab00cd to aAbBcCdD view, where A
is not(a), B=not(b), etc.. In other words capital means negation.

For instance W=00100001 on input should result to W=10010110 on
output.

It should be done as tight as only possible. Everybody welcomes ;)

WBR Dmitry.

PS.  I'll also post my solution lately.

--
Whoa Dimitry,

Once again...slowly...

I understand everything up to your example, but that's where I get
lost.  Could you go through it again showing me how you got your
output from the input given?

Thanks and Regards,

Jim

On Thu, 10 August 2000, Dmitry Kiryashov wrote:

{Quote hidden}

jimjpes.com

--
On Fri, 11 Aug 2000, Dmitry Kiryashov wrote:

{Quote hidden}

movwf   temp
clrc
rlf     temp,f
iorwf   temp,w
andlw   0x55
movwf   temp     ; 0a0b0c0d
rlf     temp,f
xorlw   0x55
iorwf   temp,w   ; or ,f

Less than 12 cycles!

maybe there's a trick or two though

Scott

--
Hi Scott. Good shot ;) Who shorter ?

WBR Dmitry.

Scott Dattalo wrote:

{Quote hidden}

--
movwf   temp    ;       temp =  00ab00cd
andlw   0x22    ;       w =      00a000c0
addwf   temp,w ;        w =      0a0b0c0d       (a+a = a0, b+0=b,
c+c=c0, d+0=d)
addlw   0x55    ;       w =     aAbBcCdD        (a+1=aA, b+1=bB,
c+1=cC, d+1=dD)

> {Original Message removed}
>
>For instance W=00100001 on input should result to W=10010110 on
>output.
>
>It should be done as tight as only possible. Everybody welcomes ;)

Interesting excersize, but what's the real-life purpose?

--
Where's dave? http://www.findu.com/cgi-bin/find.cgi?kc6ete-9

--
Hi Don.

Almost perfect ;)

WBR Dmitry.

Don Hyde wrote:
>
>         movwf   temp    ;       temp =  00ab00cd
>         andlw   0x22    ;       w =      00a000c0
>         addwf   temp,w ;        w =      0a0b0c0d       (a+a = a0, b+0=b,
> c+c=c0, d+0=d)
>         addlw   0x55    ;       w =     aAbBcCdD        (a+1=aA, b+1=bB,
> c+1=cC, d+1=dD)

--

00ab00cd
+00100010
---------------
0aAb0cCd
&01010101
----------------
0a0b0c0d
+01010101
----------------
aAbBcCdD

so, in code:

ANDLW    B'01010101'

Bob Ammerman
RAm Systems
(contract development of high performance, high function, low-level
software)

--
Bob....I hereby decree that you are the KING of binary.

all kneel and praise him.... :)

CR

{Quote hidden}

--
On Thu, 10 Aug 2000, Bob Ammerman wrote:

>
>    00ab00cd
> +00100010
>  ---------------
>   0aAb0cCd
> &01010101
>  ----------------
>   0a0b0c0d
> +01010101
> ----------------
>  aAbBcCdD
>
>
> so, in code:
>
>     ANDLW    B'01010101'

Excellent! Now I know I've been doing too much C/C++
(Also, now I know why Dmitry posted the challenge - the solution is so elegant
who cares what problem it solves? :)

Scott

--
I am sorry, but my head hurts in trying to understand this!

Bob, could you be so kind as to explain the logic and reason why this works,
rather than just stating the solution please?

tvm,
SW.

{Original Message removed}
Sure:

Here is the basic trick behind it:

Given the value (in binary)     0a,

where (a) is some bit, what happens when we add 01 (binary) to it?

Well, if 'a' is 0, then we get 01,  which is aA

And if 'a' is 1, then we get 10, which is aA

The rest of it is just applying this trick a total of 6 times:

00ab00cd + 00100010 = 0aAb0cCd    (2 times here)

0aAb0cCd & 01010101 = 0a0b0c0d    (get ready to do it again)

0a0b0c0d + 01010101 = aAbBcCdD    (4 more times)

Note that it works because there are zeros between the useful bits and
therefore carries won't happen from one to the other.

Bob Ammerman
RAm Systems
(contract development of high performance, high function, low-level
sofftware)

----- Original Message -----
From: WALSH, Scott <scott.walshPLANTRONICS.COM>
To: <PICLISTMITVMA.MIT.EDU>
Sent: Friday, August 11, 2000 5:27 AM
Subject: Re: [PIC] tiny challenge ;)

> I am sorry, but my head hurts in trying to understand this!
>
> Bob, could you be so kind as to explain the logic and reason why this
works,
> rather than just stating the solution please?
>
> tvm,
> SW.
>
> {Original Message removed}

More... (looser matching)
- Last day of these posts
- In 2000 , 2001 only
- Today
- New search...