Bits to Word?


Closed Thread
Results 1 to 7 of 7

Thread: Bits to Word?

Hybrid View

  1. #1
    Qacer's Avatar
    Qacer Guest


    Did you find this post helpful? Yes | No

    Question

    Hi mister_e,

    :-) Sorry, I was feeling a bit lazy. Plus, I don't have the most efficient computer setup in the world. Anyway, this actually the question that I can't figure out: how would I set multiple bits in a byte simultaneously? Say, I want to set bit5 to bit0 to a certain value.

    I was hoping there was something like this:

    databyte1.[5 to 0] = %101011

  2. #2
    Join Date
    Aug 2004
    Posts
    64


    Did you find this post helpful? Yes | No

    Default handling bits

    Hi:
    You can create aliases for each configuration bit. Ex:
    name1 var byte1.0
    name2 var byte1.2 etc.
    then, you can clear or set each one by

    name1 = 0, or name1 = 1

    Or you can test them:
    if name1 = 1 then do_something
    I hope this helps.
    Greetings...
    Ruben de la Pena

  3. #3


    Did you find this post helpful? Yes | No

    Default individual bit setting/clearing

    To set bit 4 on and leave the rest unchanged:

    mybyte=mybyte | %00010000 'OR function with selected bit masked ON

    To turn bit 4 off and leave the rest unchanged:

    mybyte=mybyte & %11101111 'AND function with selected bit masked OFF

    OR you can set multiple bits on or off by either ADDING or SUBTRACTING the bit weight to/from either 0 or 255 respectively.

    ------------------Picster-----------------

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. Minimizing code space
    By Tobias in forum mel PIC BASIC Pro
    Replies: 2
    Last Post: - 30th May 2009, 07:25
  3. DS2760 Thermocouple Kit from Parallax in PicBasicPro
    By seanharmon in forum mel PIC BASIC Pro
    Replies: 3
    Last Post: - 8th July 2008, 23:19
  4. calculation problem
    By nicolelawsc in forum mel PIC BASIC Pro
    Replies: 2
    Last Post: - 31st March 2006, 15:23
  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