How can i put together two int value in a new int?
int one = 1;
int two = 2;
int twelve;
void setup() {
Serial.begin (9600);
twelve = twelve + one;
twelve = twelve & two; //here i want the int "twelve" get the value 12 but i can't find the way
Serial.println (twelve);
}
void loop() {
}
Maybe we could get GolamMustafa to drop by and give a real complicated explanation of how this works involving 8-bit adders and registers and primitive assembly commands from long extinct processors
To get 12 (a decimal value) from the discrete positional factors 1 (Ten Positional Factor) and 2 (Unit Positional factor), the following approach is being presented which is still practiced in hard computer science classes!
12 = Value
Value = 1x101 + 2x100
===> Value = Ten Positional Factor (TPF) x Ten Positional Weight (TPW) + Unit Positional Factor (UPF) x Unit Positional Weight (UPW)
===> Value = TPF x TPW + UPF x UPW
while (UPF != 0)
{
IPR1 = IPR1 + UPW //IPR1 = 0x02
}
while (TPF !=0)
{
IPR2 = IPR2 + TPW //IPR2 = 0x0A
}
Value = IPR1 + IPR2 //Value = 0x0C
Serial.print(Value, DEC); //12
8085 Assembly Codes:
MVI A, 00H ; IPR1 = A = 00H
MVI C, 02H ; UPF = 02H
L1: ADD A, 01H ; UPW = 01H
DEC C
JNZ L1 ; IPR1 = A
MOV B, A ; IPR1 = B = 02H
MOV A, 00H ; IPR2 = A = 00H
MOV C, 01H ; TPF = 01H
L2: ADD A, 0AH ; TPW = 10 = 0AH
DEC C
JNZ L2
L3: ADD A, B ; A = 0CH = 00001100
L4: ;converting Binary to Decimal (BCD) using Horner Rule
for (n = 7; n >=0; x--)
{
IPBCD x 2 + bn ------> IPBCD //IPBCD = 12
DAA
}
Delta_G:
It may just be that the OP is expecting it to be harder than that. You know, overthinking it.
Maybe we could get GolamMustafa to drop by and give a real complicated explanation of how this works involving 8-bit adders and registers and primitive assembly commands from long extinct processors