PDA

View Full Version : How to add two binary variables next to each other, without mathematical operations?



CuriousOne
- 19th October 2016, 07:29
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.

HenrikOlsson
- 19th October 2016, 08:26
You need to shift the first variable "up" (to the left) 4 places and THEN add the second variable.

Result = (VAR_A << 4) + VAR_B
But yeah, it IS using a mathematical operator but why don't you want that?

/Henrik.

CuriousOne
- 19th October 2016, 08:55
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 :)

HenrikOlsson
- 19th October 2016, 10:56
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.

CuriousOne
- 19th October 2016, 12:02
never mind, it just "lost in translation", your method will work, I believe :)