Concatenation


Closed Thread
Results 1 to 8 of 8

Thread: Concatenation

  1. #1
    Join Date
    Dec 2009
    Posts
    7

    Default Concatenation

    Hi,

    I have a trivial problem, that i have been wracking my brains over for the last week. Getting dumber as i get older

    The idea is that a sequence of infra red LED's gets turned on in relation to the binary count on PortA. This also turns on an associated detector.
    Whatever the output of the detector, it gets written to the variable DataIn2.
    So, after a full 8 bits the data in DataIn2 should look like 10010110, in this case the beam has been interrupted at positions 1, 4, 6, & 7.
    The code below does this, but obviously knocks of the first bit, due to it moving the bit to the left to concatenate the variable - so the example now looks like 00010110. How do i get the complete 8 bits into the variable?



    Code:
    BinaryCount: 'Advances LED and detector 1 place
    PortA = BinCount 'Pushes Binary value of BinCount onto PortA
    Pause 10 'Pause to let detectors start up
    
    If PortB.0 = 1 Then 'monitor PortE.2 for beam break
       DataIn2 = DataIn2 + 1 'something blocking beam, write a 1 to DataIn2 variable
       DataIn2 = DataIn2<<1 'Move bit one place to left to concatinate variable
    Else 
       DataIn2 = DataIn2 + 0 'Beam clear, write a 0 to DataIn2 variable
       DataIn2 = DataIn2<<1
    EndIf
    
    If BinCount = 7 Then 
       BinCount = 0 'Reset when we get to end of LED's
       Gosub Display
    Else
    BinCount = BinCount + 1    
    EndIf
    
    Return

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


    Did you find this post helpful? Yes | No

    Default Re: Concatenation

    Code:
    If PortB.0 = 1 Then 'monitor PortE.2 for beam break
       DataIn2 = DataIn2<<1 'Move bit one place to left to concatinate variable
       DataIn2 = DataIn2 + 1 'something blocking beam, write a 1 to DataIn2 variable
    Else 
       DataIn2 = DataIn2<<1
       DataIn2 = DataIn2 + 0 'Beam clear, write a 0 to DataIn2 variable
    EndIf
    How about doing it this way?

  3. #3
    Join Date
    Oct 2005
    Location
    Sweden
    Posts
    3,604


    Did you find this post helpful? Yes | No

    Default Re: Concatenation

    Hi,
    Adding to (or removing from actually...) Jersons example, this should let you get rid of the IF/THEN construct as well
    Code:
    DataIn2 = (DataIn2 << 1) + PortB.0   ' Move bits one step to the left and add state of PortB.0 to the least significant bit.
    /Henrik.

  4. #4
    Join Date
    Dec 2009
    Posts
    7


    Did you find this post helpful? Yes | No

    Default Re: Concatenation

    Many thanks Jerson, just swapping the lines over did the trick. I really sacrificed at the alter of stupidity this week!
    HenrikOlsson, i did not know you could do this. Should save some space and speed things up.
    Many thanks to both of you for your time, really saved my sanity.

  5. #5
    Join Date
    Nov 2005
    Location
    Bombay, India
    Posts
    966


    Did you find this post helpful? Yes | No

    Default Re: Concatenation

    You're welcome. We have all been there(the altar of stupidity) at some time in our lives, haven't we?

  6. #6
    Join Date
    Dec 2009
    Posts
    7


    Did you find this post helpful? Yes | No

    Default Re: Concatenation

    Hi Jerson / HenrikOlsson,

    Not sure what happened to my spelling this week either. 'alter' - what is wrong with me! Maybe i should get checked for early onset Alzheimers - ah, maybe not, i can spell Alzheimers!
    Having looked through my code, I've realised (English spelling), that concatenation is spelled incorrectly as well, argghhh! Maybe it's the wine - surely not - it can't be the wine - oh god , not the wine!!

    P.S. HenrikOlsson, thanks again, that one line of code is beautiful - did i spell that correctly, phew!

  7. #7
    Join Date
    Dec 2012
    Location
    Tennessee
    Posts
    262


    Did you find this post helpful? Yes | No

    Default Re: Concatenation

    I thought it was spelled Oldtimer's.... Everyone needs a laugh

  8. #8
    Join Date
    Dec 2009
    Posts
    7


    Did you find this post helpful? Yes | No

    Default Re: Concatenation

    Hey, steady on, I'm not that old. Oh, actually I might be.
    Nurse, quick, the screens!
    Last edited by galliumman; - 14th February 2013 at 23:07. Reason: Doh, spelling mistake!

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