4 Bytes one button press


Closed Thread
Results 1 to 6 of 6

Hybrid View

  1. #1


    Did you find this post helpful? Yes | No

    Default A byte or a word ?

    Hi Art

    Thanks so much that's a very helpful tip indeed!

    I haven't tried this yet but I will as soon as I get a chance and feedback asap.

    Just curious if I need to declare CHECKSUM as a byte or a word ?
    For example if the byte is 255 Decimal aka 11111111 Binary, would there be any overflow into a second byte

    Kind regards

    Dennis

  2. #2
    Join Date
    Aug 2003
    Posts
    985


    Did you find this post helpful? Yes | No

    Default

    The checksum is a byte.
    If you XOR a number with any other number, there can never be an overflow.

    The XOR operation tests each bit of the two bytes operated on.
    If the first two bits of each value are the same, the first bit of the new byte is 0.
    If the first two bits of each value are different, the first bit of the new number is 1.

    0000111 XOR
    1010101 =

    1010010

  3. #3


    Did you find this post helpful? Yes | No

    Default ok ..Hi

    Hi Art

    Once again thanks for the explanation and reply :-)

    Mmm the eXclusive OR so the truth table then looks like this ...

    A B Result
    1 1 0
    1 0 1
    0 1 1
    0 0 0

    So ....
    The XOR operator returns a 1 when the value of either the first bit or the second bit is a 1.

    The XOR operator returns a 0 when neither or both of the bits is 1.

    And for a variable swap we could do something like this then ?
    X var byte
    y var byte

    x = x xor y
    y = x xor y
    x = x xor y

    which would be something to consider but NOT to do :-) (just wondering how PBP would react to that one ?)
    See here:
    http://betterexplained.com/articles/...les-using-xor/
    and here:
    http://www.topbits.com/xor-encryption.html

    Thanks so much one again
    Will definitely give it a bash and post some feedback of the results :-)

    Kind regards

    Dennis

  4. #4


    Did you find this post helpful? Yes | No

    Default ok ....

    Hi Art

    Once again thanks for the explanation and reply :-)

    Mmm the eXclusive OR so the truth table then looks like this ...

    A B Result
    1 1 0
    1 0 1
    0 1 1
    0 0 0

    So ....
    The XOR operator returns a 1 when the value of either the first bit or the second bit is a 1.

    The XOR operator returns a 0 when neither or both of the bits is 1.

    And for a variable swap we could do something like this then ?
    X var byte
    y var byte

    x = x xor y
    y = x xor y
    x = x xor y

    which would be something to consider but NOT to do :-) (just wondering how PBP would react to that one ?)
    See here:
    http://betterexplained.com/articles/...les-using-xor/
    and here:
    http://www.topbits.com/xor-encryption.html

    Thanks so much once again!

    Will definitely give it a bash and post some feedback of the results :-)

    Kind regards

    Dennis

Similar Threads

  1. multi functions button press
    By malwww in forum mel PIC BASIC Pro
    Replies: 6
    Last Post: - 27th May 2009, 00:12
  2. Using Sleep
    By elec_mech in forum mel PIC BASIC Pro
    Replies: 2
    Last Post: - 17th August 2008, 04:05
  3. Button press and press & hold how to ?
    By GrandPa in forum mel PIC BASIC Pro
    Replies: 9
    Last Post: - 22nd August 2007, 03:37
  4. 3 HPWM channels
    By docwisdom in forum mel PIC BASIC Pro
    Replies: 9
    Last Post: - 4th April 2006, 02:43
  5. Code check -- button not working
    By docwisdom in forum mel PIC BASIC Pro
    Replies: 12
    Last Post: - 2nd March 2006, 22:43

Members who have read this thread : 0

You do not have permission to view the list of names.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts