reading first four bits of a byte


Closed Thread
Results 1 to 3 of 3
  1. #1
    Join Date
    Mar 2006
    Posts
    13

    Default reading first four bits of a byte

    if i have a hex byte, say "FF", is there something to read the first 4 bits and last 4 bits individually? or put it into another variable? Something simliar to reading a WORD variable using ".highbyte" and ".lowbyte"

    I am currently doing this this way:

    nibholderLow.0 = myvar.0
    nibholderLow.1 = myvar.1
    nibholderLow.2 = myvar.2
    nibholderLow.3 = myvar.3

    nibholderHigh.0 = myvar.4
    nibholderHigh.1 = myvar.5
    nibholderHigh.2 = myvar.6
    nibholderHigh.3 = myvar.7

    Basically, nibholderLow is a variable which holds first 4 bits of the byte FF, (ie. 15) and the other one, nibholderHigh holds the other F.

    the variable myvar is constantly changing, I can't declare this conversion at the very top.

  2. #2
    Join Date
    Jul 2003
    Location
    Colorado Springs
    Posts
    4,959


    Did you find this post helpful? Yes | No

    Default

    nibholderHigh = myvar >> 4
    nibholderLow = myvar & $F
    <br>
    DT

  3. #3
    Join Date
    Mar 2006
    Posts
    13


    Did you find this post helpful? Yes | No

    Default

    ahh thanks! so simple yet it never occured to me.

    much thanks again!

Similar Threads

  1. Bits, Bytes Words and Arrays
    By Melanie in forum FAQ - Frequently Asked Questions
    Replies: 24
    Last Post: - 14th June 2016, 08:55
  2. byte compression
    By Norbert in forum mel PIC BASIC Pro
    Replies: 6
    Last Post: - 16th June 2007, 19:04
  3. Microcontroller with 2 way paging application problem
    By oneohthree in forum mel PIC BASIC Pro
    Replies: 30
    Last Post: - 20th April 2007, 18:27
  4. 16F877 RAM Question
    By Art in forum mel PIC BASIC Pro
    Replies: 8
    Last Post: - 6th August 2005, 12:47
  5. error on compiling
    By parker in forum mel PIC BASIC Pro
    Replies: 0
    Last Post: - 16th June 2005, 15:31

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