How to add two binary variables next to each other, without mathematical operations?


Closed Thread
Results 1 to 5 of 5
  1. #1
    Join Date
    Feb 2013
    Posts
    1,078

    Default How to add two binary variables next to each other, without mathematical operations?

    The question is.

    Say I have variable A, which is 1110 in BIN. And have variable B, which is 1101 in BIN. I want to convert them to single variable, which will read as 11101101 in BIN, by just adding them next to each other. If I use "+", then binary values of these variables will be added, so mathematicaly, result will be correct, but this is not what I need.

  2. #2
    Join Date
    Oct 2005
    Location
    Sweden
    Posts
    3,521


    Did you find this post helpful? Yes | No

    Default Re: How to add two binary variables next to each other, without mathematical operatio

    You need to shift the first variable "up" (to the left) 4 places and THEN add the second variable.
    Code:
    Result = (VAR_A << 4) + VAR_B
    But yeah, it IS using a mathematical operator but why don't you want that?

    /Henrik.

  3. #3
    Join Date
    Feb 2013
    Posts
    1,078


    Did you find this post helpful? Yes | No

    Default Re: How to add two binary variables next to each other, without mathematical operatio

    Because this binary variable is actually a pattern for dot matrix led display.

    Matrix is 10 pixels wide, 7 pixels in height. So say, I want to display two symbols on it, each are stored in separate variable, I have to place them next to each other

  4. #4
    Join Date
    Oct 2005
    Location
    Sweden
    Posts
    3,521


    Did you find this post helpful? Yes | No

    Default Re: How to add two binary variables next to each other, without mathematical operatio

    I understand that you want to place the two nibbles next to each other within the byte but I don't understand why you want to do it without mathematical operation.
    Anyway, try the suggested method, it does what you're asking for.

  5. #5
    Join Date
    Feb 2013
    Posts
    1,078


    Did you find this post helpful? Yes | No

    Default Re: How to add two binary variables next to each other, without mathematical operatio

    never mind, it just "lost in translation", your method will work, I believe

Similar Threads

  1. Mathematical calculation
    By amindzo in forum mel PIC BASIC Pro
    Replies: 16
    Last Post: - 27th October 2013, 00:07
  2. how to get the mathematical function sin
    By minssss in forum mel PIC BASIC Pro
    Replies: 9
    Last Post: - 18th July 2010, 17:13
  3. Multiple operations at once?
    By sphinxifm in forum mel PIC BASIC Pro
    Replies: 7
    Last Post: - 16th June 2008, 07:53
  4. Mathematical problem
    By iugmoh in forum General
    Replies: 2
    Last Post: - 25th January 2008, 18:24
  5. Mathematical Precedence
    By keithdoxey in forum mel PIC BASIC Pro
    Replies: 4
    Last Post: - 6th October 2006, 21:44

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