Byte Variable modifiers


Closed Thread
Results 1 to 4 of 4
  1. #1
    bugmee's Avatar
    bugmee Guest

    Default Byte Variable modifiers

    Hello,

    After looking up modifiers for variables in the manual I saw that there is no way to simply retrieve the lowest 4 bits of a byte, and the highest 4 bits of a byte.

    Is this actually available?

    If now, what is the easiest way to get the lowest and highest 4 bits of a byte variable?

    Thanks

  2. #2
    Join Date
    Oct 2003
    Location
    holland
    Posts
    251


    Did you find this post helpful? Yes | No

    Default

    And them with %11110000 for the 4 higher bits or and them with %00001111 for the for lower bits.
    For the 4 higher bits you could shift them 4 times right to get them on the lower positions
    Last edited by mat janssen; - 12th March 2010 at 10:37.

  3. #3
    Join Date
    Jan 2009
    Location
    California, USA
    Posts
    323


    Did you find this post helpful? Yes | No

    Default

    Use the bitwise operator "&" like this:

    Code:
    mynibble = mybyte & %00001111     'Put the lower 4 bits into mynibble
    
    myothernibble = mybyte & %11110000     'Put the upper 4 bytes into myothernibbe
    steve


    Dohh! Mat beat me to it.
    Last edited by Byte_Butcher; - 12th March 2010 at 15:27. Reason: slow on the draw

  4. #4
    Join Date
    Mar 2010
    Location
    Serbia
    Posts
    2


    Did you find this post helpful? Yes | No

    Default

    You could do this:

    Code:
    highbits = yourbyte / 16
    lowbits = yourbyte // 16
    Last edited by misamilanovic; - 12th March 2010 at 16:36.

Similar Threads

  1. LCD freeze
    By harryweb in forum mel PIC BASIC Pro
    Replies: 3
    Last Post: - 5th October 2009, 08:01
  2. Memory use - how much do you use?
    By keymuu in forum mel PIC BASIC Pro
    Replies: 16
    Last Post: - 10th June 2009, 22:39
  3. byte compression
    By Norbert in forum mel PIC BASIC Pro
    Replies: 6
    Last Post: - 16th June 2007, 18:04
  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. 16F877 RAM Question
    By Art in forum mel PIC BASIC Pro
    Replies: 8
    Last Post: - 6th August 2005, 11:47

Members who have read this thread : 1

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