An easy way to get bits to byte


Closed Thread
Results 1 to 8 of 8
  1. #1
    Join Date
    Feb 2012
    Location
    PERTH AUSTRALIA
    Posts
    838

    Default An easy way to get bits to byte

    Hi guys i seem to recall there was a simply way to do this but i cant recall how

    number is stored as 3 bits to represent 0 -7 value as part of a stored byte
    i need display byte to be a bit representation

    eg
    stored bit0,1,2 = value 0 = display byte- all bits off
    stored bit0,1,2 = value 1 = display byte- bit0 on ,display byte bits 1-7 off
    stored bit0,1,2 = value 2 = display byte- bit1 on, display byte bit0,2-7 off
    stored bit0,1,2 = value 3 = display byte- bit2 on, display byte bit0,1,3-7 off
    stored bit0,1,2 = value 4 = display byte- bit3 on, display byte bit0-2,4-7 off
    stored bit0,1,2 = value 5 = display byte- bit4 on, display byte bit0-3,5-7 off
    stored bit0,1,2 = value 6 = display byte- bit5 on, display byte bit0-4,6-7 off
    stored bit0,1,2 = value 7 = display byte- bit6 on, display byte bit0-5,7 off

  2. #2
    Join Date
    Nov 2005
    Location
    Bombay, India
    Posts
    947


    Did you find this post helpful? Yes | No

    Default Re: An easy wasy to get bits to byte

    Isn't that the DCD command you're talking about?

  3. #3
    Join Date
    Feb 2012
    Location
    PERTH AUSTRALIA
    Posts
    838


    Did you find this post helpful? Yes | No

    Default Re: An easy wasy to get bits to byte

    yep , could not think of the command , cheers jerson

  4. #4
    Join Date
    Feb 2012
    Location
    PERTH AUSTRALIA
    Posts
    838


    Did you find this post helpful? Yes | No

    Default Re: An easy wasy to get bits to byte

    trouble is value of 0 turns on bit 0 in the display byte

  5. #5
    Join Date
    Feb 2012
    Location
    PERTH AUSTRALIA
    Posts
    838


    Did you find this post helpful? Yes | No

    Cool Re: An easy wasy to get bits to byte

    Code:
     val = DCD (((Event_Conf_Byte4 & $1C) >>2) - 1)
    this did the job , but the output is always on even if the value = 0 , so just worked arround it for what i need

  6. #6
    Join Date
    Aug 2003
    Posts
    985


    Did you find this post helpful? Yes | No

    Default Re: An easy wasy to get bits to byte

    It sounds easier than what you posted above, but I don’t know if I’m reading your first post right.

    "
    stored bit0,1,2 = value 4 = display byte- bit3 on, display byte bit0-2,4-7 off

    Is that the same as saying:
    displaybyte.bit3 is set and all other bits are off, so in a different byte, set it’s bits 0,1 & 2 to a binary 4 so the new byte is 00000100 ?

  7. #7
    Join Date
    Feb 2012
    Location
    PERTH AUSTRALIA
    Posts
    838


    Did you find this post helpful? Yes | No

    Default Re: An easy way to get bits to byte

    hi art
    for what i really i needed the lowest value was 1 highest was 6 so the -1 option works ok , in this instance using dcd is ok

    0 was not a possiblity in this setting
    but if the value of 0 was to show nothing then dcd is not going work
    cheers

    sheldon

    BTW hows your light show project going with the neon lights

  8. #8
    Join Date
    Aug 2003
    Posts
    985


    Did you find this post helpful? Yes | No

    Default Re: An easy way to get bits to byte

    So long as it’s working I suppose you’re happy!

    Are you subscribed to me on YouTube? I didn’t think I posted it here.
    From what I said on YouTube my ideas have changed a bit, and it’s a bit of financial commitment.
    I want to use red, green and blue neon tubes, and dim/blend them for different colours.

    Once the switching is sorted out with solid state relays I don’t think it’s a real big project in any way other than paying for it

Similar Threads

  1. Problem with bits in byte array....
    By HenrikOlsson in forum mel PIC BASIC Pro
    Replies: 15
    Last Post: - 19th October 2011, 07:27
  2. Changing bits in a byte for multiple output
    By tazntex in forum Serial
    Replies: 3
    Last Post: - 11th August 2008, 20:10
  3. Accessing several bits together in a byte or word...
    By rossfree in forum mel PIC BASIC Pro
    Replies: 2
    Last Post: - 7th May 2007, 19:07
  4. Bits in Byte Arrays
    By crhomberg in forum mel PIC BASIC Pro
    Replies: 1
    Last Post: - 24th April 2007, 23:37
  5. reading first four bits of a byte
    By kamet in forum mel PIC BASIC Pro
    Replies: 2
    Last Post: - 2nd January 2007, 09:50

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