First, some clarification - two numbers aren't "hex" or "binary" or "decimal" - they're just numbers. You can choose to represent them however you like. I'll assume they're just 4-byte integers for now.
The cop-out is to manipulate their representations, which is what you're doing anyway. So you can do something like this:
def binaryAppend(num1, num2):
return int(dec2bin(str(num1)) + dec2bin(str(num2)))
This takes two integers, converts them to a string representation in decimal, then converts that to binary, then concatenates them together and returns that as an integer.
This is slow, however.
You can do this instead:
int binaryLength(char num) {
int l = 0;
while(num) {
num >>= 1;
l += 1;
}
return l;
}
This returns the number of binary digits in the number (shifts to the right until the number is 0). Then your concat function will look like this (You stated chars as input in your code, so I'll use chars here):
uint32 concatBin(char num1, char num2) {
return num1 | (num2 << binaryLength(num1));
}
Example usage:
> concatBin(1, 2)
5
1 is 1 in binary, 2 is 10, the concat is 101, which is indeed 5 in decimal.