math function to change a value 1- 8 to a bit representation


Closed Thread
Results 1 to 9 of 9

Hybrid View

  1. #1
    Join Date
    Apr 2011
    Location
    Welches, Oregon
    Posts
    198


    Did you find this post helpful? Yes | No

    Default Re: math function to change a value 1- 8 to a bit representation

    Quote Originally Posted by longpole001 View Post
    would it be
    if value > 2 then VAR.0[VALUE - 1]
    cos if value below 2 would be incorrect bit ??
    I'm a noob myself, but no... The VAR.0[] syntax is a way of addressing each bit and, while it affects the value of the byte, the bits do not interact.
    Some examples:

    VAR= %00000000 : VAR.0[0] = 1 : 'VAR NOW EQUALS %00000001
    VAR= %00000100 : VAR.0[0] = 1 : 'VAR NOW EQUALS %00000101
    VAR= %10100001 : VAR.0[1] = 1 : 'VAR NOW EQUALS %10100011
    VAR= %11111100 : VAR.0[7] = 0 : 'VAR NOW EQUALS %01111101

    As you can see by the last example, turning "off" bits is the same, only assign a 0. Reassigning a bit, already set (or cleared) has no effect.

  2. #2
    Join Date
    May 2008
    Location
    Italy
    Posts
    825


    Did you find this post helpful? Yes | No

    Default Re: math function to change a value 1- 8 to a bit representation

    Hmmm....Answer = answer < 1
    Just a typo! What else if not shift left.

    Cheers

    Al.
    All progress began with an idea

Similar Threads

  1. Logaritmic ADC representation
    By RFsolution in forum mel PIC BASIC Pro
    Replies: 4
    Last Post: - 5th April 2010, 11:05
  2. 32 bit math
    By fnovau in forum General
    Replies: 4
    Last Post: - 12th February 2008, 23:55
  3. Averaging 16 bit values without using 32 bit math
    By sirvo in forum mel PIC BASIC Pro
    Replies: 2
    Last Post: - 5th October 2007, 22:18
  4. 32 bit math
    By Charles Linquis in forum mel PIC BASIC Pro
    Replies: 12
    Last Post: - 28th August 2006, 13:34
  5. not quite understanding the MATH function
    By Rhatidbwoy in forum mel PIC BASIC Pro
    Replies: 10
    Last Post: - 17th January 2006, 20:20

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