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.
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.
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 :)
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.
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 :)