Searching \ for 'Inverting binary word' in subject line. ()
Make payments with PayPal - it's fast, free and secure! Help us get a faster server
FAQ page: www.piclist.com/techref/index.htm?key=inverting+binary
Search entire site for: 'Inverting binary word'.

Truncated match.
PICList Thread
'Inverting binary word'
1999\05\03@171902 by Andreas Magnusson

picon face
part 0 1781 bytes
<META content=text/html;charset=iso-8859-1 http-equiv=Content-Type>
<META content='"MSHTML 4.72.3110.7"' name=GENERATOR>
</HEAD>
<BODY bgColor=#ffffff>
<DIV><FONT color=#000000 size=2>Hello all!</FONT></DIV>
<DIV><FONT color=#000000 size=2></FONT>&nbsp;</DIV>
<DIV><FONT color=#000000 size=2>I have a problem. I am programming a PIC. In the
program I load a value from portb to the register TANKOD. The value from portb
tell me wich button that is pressed down on a keypad. If button 3 is pressed, 3
will be the value of portb.</FONT></DIV>
<DIV><FONT color=#000000 size=2></FONT>&nbsp;</DIV>
<DIV><FONT color=#000000 size=2>My problem is that the keypad use &quot;negative
logic&quot; or something like that. A 0 is a 1 and a 1 is a 0. So i want to
invert the register.</FONT></DIV>
<DIV><FONT color=#000000 size=2></FONT>&nbsp;</DIV>
<DIV><FONT size=2>11111100&nbsp;&nbsp;&nbsp; =&gt;&nbsp;&nbsp;&nbsp;
00000011</FONT></DIV>
<DIV><FONT color=#000000 size=2></FONT>&nbsp;</DIV>
<DIV><FONT color=#000000 size=2></FONT>&nbsp;</DIV>
<DIV><FONT color=#000000 size=2>Any Idea how I can do this in a easy
way.</FONT></DIV>
<DIV><FONT color=#000000 size=2></FONT>&nbsp;</DIV>
<DIV><FONT color=#000000 size=2></FONT>&nbsp;</DIV>
<DIV><FONT color=#000000 size=2>Tnx&nbsp;&nbsp;&nbsp; /Andreas
Magnusson</FONT></DIV></BODY></HTML>

</x-html>

1999\05\03@174351 by Mike Henning

flavicon
face
part 0 2178 bytes
<META content=text/html;charset=iso-8859-1 http-equiv=Content-Type><!DOCTYPE HTML PUBLIC "-//W3C//DTD W3 HTML//EN">
<META content='"MSHTML 4.72.3110.7"' name=GENERATOR>
</HEAD>
<BODY bgColor=#ffffff>
<BLOCKQUOTE
style="BORDER-LEFT: #000000 solid 2px; MARGIN-LEFT: 5px; PADDING-LEFT: 5px">
   <DIV>&nbsp;</DIV>
   <DIV><FONT color=#000000 size=2>I have a problem. I am programming a PIC. In
   the program I load a value from portb to the register TANKOD. The value from
   portb tell me wich button that is pressed down on a keypad. If button 3 is
   pressed, 3 will be the value of portb.</FONT></DIV>
   <DIV><FONT color=#000000 size=2></FONT>&nbsp;</DIV>
   <DIV><FONT color=#000000 size=2>My problem is that the keypad use
   &quot;negative logic&quot; or something like that. A 0 is a 1 and a 1 is a
   0. So i want to invert the register.</FONT></DIV>
   <DIV><FONT color=#000000 size=2></FONT>&nbsp;</DIV>
   <DIV><FONT size=2>11111100&nbsp;&nbsp;&nbsp; =&gt;&nbsp;&nbsp;&nbsp;
   00000011</FONT></DIV>
   <DIV><FONT color=#000000 size=2></FONT>&nbsp;</DIV>
   <DIV><FONT color=#000000 size=2></FONT>&nbsp;</DIV>
   <DIV><FONT color=#000000 size=2>Any Idea how I can do this in a easy
   way.</FONT>&nbsp;</DIV>
   <DIV>&nbsp;</DIV>
   <DIV><FONT color=#000000 size=2>Something like this should work for
   you.</FONT></DIV>
   <DIV>&nbsp;</DIV>
   <DIV><FONT color=#000000 size=2>movlw&nbsp;&nbsp;&nbsp; .255</FONT></DIV>
   <DIV><FONT color=#000000 size=2>xorwf&nbsp;&nbsp;&nbsp; portb,w</FONT></DIV>
   <DIV><FONT color=#000000 size=2>movwf&nbsp;&nbsp;&nbsp;
tankod</FONT></DIV></BLOCKQUOTE></BODY></HTML>

</x-html>

1999\05\03@175029 by David W. Duley

picon face
In a message dated 5/3/99 2:19:31 PM Pacific Daylight Time,
spam_OUTandreas.mTakeThisOuTspamTELIA.COM writes:

<< Hello all!

I have a problem. I am programming a PIC. In the program I load a value from
portb to the register TANKOD. The value from portb tell me wich button that
is pressed down on a keypad. If button 3 is pressed, 3 will be the value of
portb.

My problem is that the keypad use "negative logic" or something like that. A
0 is a 1 and a 1 is a 0. So i want to invert the register.

11111100    =>    00000011


Any Idea how I can do this in a easy way.


Tnx    /Andreas Magnusson
 >>
Hi Andreas,

How about:


       xorlw   b'11111111'                             ;exclusive OR W with
all 1's


W register should contain the value obtained from port B.
when finished, the W reg will be inverted.


Dave Duley



1999\05\03@181731 by Mike Keitz

picon face
On Mon, 3 May 1999 17:42:37 -0400 Mike Henning <.....mikehgKILLspamspam@spam@FUSE.NET> writes:

>    movlw    .255
>    xorwf    portb,w
>    movwf    tankod

Use the COMF instruction if the value to be inverted is in a file
register.  If it is in W, XORLW with 255 (hex FF).


___________________________________________________________________
You don't need to buy Internet access to use free Internet e-mail.
Get completely free e-mail from Juno at http://www.juno.com/getjuno.html
or call Juno at (800) 654-JUNO [654-5866]

1999\05\04@034534 by Dr. Imre Bartfai

flavicon
face
Hi,
use
       COMF    TANKOD,F
or
       COMF    PORTB,W
       MOVWF   TANKOD

I hope this helps.
Imre


On Mon, 3 May 1999, Andreas Magnusson wrote:

> Hello all!
>
> I have a problem. I am programming a PIC. In the program I load a value from p
ortb to the register TANKOD. The value from portb tell me wich button that is pr
essed down on a keypad. If button 3 is pressed, 3 will be the value of portb.
>
> My problem is that the keypad use "negative logic" or something like that. A 0
is a 1 and a 1 is a 0. So i want to invert the register.
>
> 11111100    =>    00000011
>
>
> Any Idea how I can do this in a easy way.
>
>
> Tnx    /Andreas Magnusson
>

1999\05\04@040650 by Sebastián Dols

flavicon
face
part 0 16 bytes
</x-html>

1999\05\04@083445 by paulb

flavicon
face
Various suggestions to XOR with .255 or b'11111111' or 0xff noted.

 I suggest the most reliable and actually shortest way to represent the
value "all ones" is in fact always ...
-1
(minus one).

 Anyone suggest a reason why not?
--
 Cheers,
       Paul B.

1999\05\04@103514 by Dan Larson

flavicon
face
On Tue, 4 May 1999 22:32:22 +1000, Paul B. Webster VK2BZC wrote:

>Various suggestions to XOR with .255 or b'11111111' or 0xff noted.
>
>  I suggest the most reliable and actually shortest way to represent the
>value "all ones" is in fact always ...
> -1
>(minus one).
>
>  Anyone suggest a reason why not?

Can't tell you why not, but I can sure tell you *why* from experience!
Darned, if it isn't one of the hardest bugs to notice when you accidentally
drop one of those 1's! ... especially when there are no other binary constants
near by in the source to use as a visual guide.

I *do* like to use binary constants a lot though for masks, because I never
really have been able to visualize the binary value all hex numbers
equally well.

Too bad they don't teach children alternate numbering systems from age
5 on up.  I suspect HEX and binary would be more natural then....


Dan

1999\05\04@110850 by Andy Kunz

flavicon
face
>Too bad they don't teach children alternate numbering systems from age
>5 on up.  I suspect HEX and binary would be more natural then....

"They" do if you home school <G>!

I learned quite a few common (and uncommon) number systems in my public
school days, plus multiplication tables up through 19 x 19. (I'm a little
rusty on the non-power-of-two ones these days, though <G>)

Andy
==================================================================
  Montana Design Tech Support - http://www.montanadesign.com
==================================================================

1999\05\05@063405 by Caisson

flavicon
face
> Van: Paul B. Webster VK2BZC <paulbspamKILLspammidcoast.com.au>
> Aan: .....PICLISTKILLspamspam.....MITVMA.MIT.EDU
> Onderwerp: Re: Inverting binary word
> Datum: dinsdag 4 mei 1999 14:32

Hello Paul,

> Various suggestions to XOR with .255 or b'11111111' or 0xff noted.
>
>   I suggest the most reliable and actually shortest way to represent the
> value "all ones" is in fact always ...
>  -1
> (minus one).
>
>   Anyone suggest a reason why not?

Using a pre/postfix that designates the Number-base has my vote.  Using the
same Number-base thru-out the whole program (exept where another
representation is called for, like using binary numbers with
bit-manipulations) gets another vote.  Not depending on the RADIX setup
gets a strong Thumbs-Up.

So, the 0xFF gets my vote (notice the lower-case "x" and uppercased
Hex-digits :-) . Short,  and easy convertible to a binary representation.

Another option would be to create a (One command !) macro called "Not" ...
A one-time writing of  XORLW b'11111111'  becomes less of a problem.

Greetz,
 Rudy Wieser

1999\05\05@091305 by paulb

flavicon
face
Caisson wrote:

> Using a pre/postfix that designates the Number-base has my vote.
> Using the same Number-base thru-out the whole program (except where
> another representation is called for, like using binary numbers with
> bit-manipulations)

 Hmmm.  You've contradicted yourself immediately!

 My personal preference is in fact to use number bases according to
their strengths.  For a calculation which I would perform in decimal
(e.g., on a calculator), I use decimal specification of the numbers.  I
might tend to use binary for bitmasks, but it isn't really terribly
readable, so I generally use hex.  This appears to be what you are
saying you *actually* do.

> gets another vote.  Not depending on the RADIX setup gets a strong
> Thumbs-Up.

 As I don't really think in hex by default, decimal seems a good
default radix.

> So, the 0xFF gets my vote (notice the lower-case "x" and uppercased
> Hex-digits :-) .

 That is the style I generally use for hex.  Only because so many
people appear addicted to this Intel crap notation.  Motorola convention
($ for hex, % for binary) is *immesurably* cleaner, including parsing.

 The point I was *actually* making, is that using the "-1" convention,
you can ignore the radix! -1 = -0x1 = b'-1' you see.

 Also note:  I never mentioned octal ;-)
--
 Cheers,
       Paul B.

1999\05\06@061345 by Caisson

flavicon
face
> Van: Paul B. Webster VK2BZC <EraseMEpaulbspam_OUTspamTakeThisOuTmidcoast.com.au>
> Aan: PICLISTspamspam_OUTMITVMA.MIT.EDU
> Onderwerp: Re: Inverting binary word
> Datum: woensdag 5 mei 1999 15:10

Hello Paul,

> Caisson wrote:
>
> > Using a pre/postfix that designates the Number-base has my vote.
> > Using the same Number-base thru-out the whole program (except where
> > another representation is called for, like using binary numbers with
> > bit-manipulations)
>
>   Hmmm.  You've contradicted yourself immediately!

Not really.  I just tried to say that You/I/Anyone should not take another
number-base with every instruction, but not make "take one numberbase
thruout the program" a Law.

{Quote hidden}

I'm mostly working in Hex.  A Subroutine (based on my HEX Radix.) would not
work with your program (based on a Dec Radix) ...

> > So, the 0xFF gets my vote (notice the lower-case "x" and uppercased
> > Hex-digits :-) .
>
>   That is the style I generally use for hex.  Only because so many
> people appear addicted to this Intel crap notation.  Motorola convention
> ($ for hex, % for binary) is *immesurably* cleaner, including parsing.

That's an opinion.  I've worked with both (and with versions that post-fix
the number-base), and do not have a real preference ...  Although I would
like a standard convention :-)

>   The point I was *actually* making, is that using the "-1" convention,
> you can ignore the radix! -1 = -0x1 = b'-1' you see.

It's a good one.  But writing the number including it's number-base has my
preference.

>   Also note:  I never mentioned octal ;-)

My god !  I learned to enter machine-code (8080) this way. Geez, I'm
getting Old.

Greetz,
 Rudy Wieser

1999\05\07@121112 by John Payson

flavicon
face
|  My personal preference is in fact to use number bases according to
|their strengths.  For a calculation which I would perform in decimal
|(e.g., on a calculator), I use decimal specification of the numbers.  I
|might tend to use binary for bitmasks, but it isn't really terribly
|readable, so I generally use hex.  This appears to be what you are
|saying you *actually* do.

I generally use decimal notation for constants that represent counts
or quantities, and hex for constants whose bit representation is sig-
nificant.

For example,

       movlw   16
       movwf   Count
Loop:
       movlw   $30
       xorwf   PORTB
       decfsz Count
        goto   Loop

The constant in the first line could have been written as $10, but
its real meaning is 'sixteen'.  The number in the fourth line could
have been written as 48, but its really meaning is 'bits 4 and 5
set; others clear'.

> gets another vote.  Not depending on the RADIX setup gets a strong
> Thumbs-Up.

|  As I don't really think in hex by default, decimal seems a good
|default radix.

Decimal is the proper default radix (if you want to use Octal or
binary, I suppose you could).  Hex is NOT a good default radix.
If I write "movlw AC" or "movlw 5D", what does those mean?  If I'd
have to write "movlw 0AC" or "movlw 5Dh" to make the meaning clear,
why should I not just use the Motorla-standard notation "movlw $AB"
which is just as concise but more meaningful?

> So, the 0xFF gets my vote (notice the lower-case "x" and uppercased
> Hex-digits :-) .

|  That is the style I generally use for hex.  Only because so many
|people appear addicted to this Intel crap notation.  Motorola convention
|($ for hex, % for binary) is *immesurably* cleaner, including parsing.

One of the beauties of the Motorola notation is that numbers can
be written out to their actual length.  Eight-bit quantities get
written as two digits; sixteen-bit quantities get written as four.
With the Intel notation, 8-bit quantities 00h-9Fh get written as
two digits while 0A0h-0FFh take three.  I have yet to see anyone
state a reason why alpha suffixes are better than non-alpha pref-
ixes.

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