Lower 4 Bits?


Closed Thread
Results 1 to 5 of 5

Thread: Lower 4 Bits?

  1. #1

    Default Lower 4 Bits?

    I am trying to "mask" or "isolate" the lower 4 bits of a byte, and having trouble.I tried using the example on page 26 of the PBP manual:

    SecOnes var byte 'should be NIBBLE?
    SecOnes = Seconds & $0f

    This gives a "Bad Expression" error when compiling. Can someone help, please?
    Thank you

  2. #2
    Join Date
    Jul 2005
    Location
    Midwest
    Posts
    81


    Did you find this post helpful? Yes | No

    Default

    Try-
    SecOnes var byte 'should be NIBBLE?
    Seconds var byte
    SecOnes = Seconds & $0f

    Or-
    SecOnes var byte 'should be NIBBLE?
    SecOnes = SecOnes & $0f

  3. #3


    Did you find this post helpful? Yes | No

    Default

    I forgot to add that there already is a SECONDS variable, and it still has the error. Why does it say $0f ???

  4. #4
    Join Date
    Jul 2003
    Posts
    2,405


    Did you find this post helpful? Yes | No

    Default

    This should not return any errors.
    Code:
    SecOnes var byte
    Seconds var byte
    SecOnes = Seconds & $0f
    Of course the result will be unknown since none of the variables are initialized, but it
    definitely should not return an error.

    Why does it say $0f ???
    Because a value of $0F (%00001111) ANDed with another 8-bit value will return all
    0's in the upper 4-bits of the result MASKing the upper 4-bits out.
    Regards,

    -Bruce
    tech at rentron.com
    http://www.rentron.com

  5. #5


    Did you find this post helpful? Yes | No

    Default

    Thank you, Bruce for the explanation. I now understand how it works. I failed to explain that I'm trying to "add-on" (within the Main portion of my program) to DT's Elapsed_INT-18. That's why I said the Seconds variable was already declared. So, when I declare it again, I get the redefinition error. I'll try adding the SecOnes stuff to HIS program!

Similar Threads

  1. Bits, Bytes Words and Arrays
    By Melanie in forum FAQ - Frequently Asked Questions
    Replies: 24
    Last Post: - 14th June 2016, 07:55
  2. Reading in Manchester code
    By brid0030 in forum Code Examples
    Replies: 0
    Last Post: - 10th March 2009, 21:55
  3. Replies: 5
    Last Post: - 30th April 2008, 20:01
  4. Microcontroller with 2 way paging application problem
    By oneohthree in forum mel PIC BASIC Pro
    Replies: 30
    Last Post: - 20th April 2007, 17:27
  5. error on compiling
    By parker in forum mel PIC BASIC Pro
    Replies: 0
    Last Post: - 16th June 2005, 14:31

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