# Thread: easiet way to put digits at the left side of number

1. ## easiet way to put digits at the left side of number

lets say i have a long type variable
for example
Code:
`long x =43343539839853583;`
im looking for the best algorithm to put 111 for example at the left of the number(
Code:
`final result 11143343539839853583)`

2. So I guess we're assuming that a long is 64 bits? I would just do this: x += 11100000000000000000;

3. If the number of digits will vary, then you need to look into using log10 to figure out the number of digits (or a division loop), and pow to get something to multiply it by to get the right number of zeros after the 111. Then you can add.

4. Originally Posted by itsme86
So I guess we're assuming that a long is 64 bits? I would just do this: x += 11100000000000000000;
Even if we were assuming that, then the constant is still missing the L suffix and is therefore of type int. Unless the compiler he is using treats both int and long as 64 bit (which I don't believe can be the case) then the first line of code he posted is a fail.

5. Convert to string, stick "111" at the front, convert back to long?

6. Like this...

Code:
```char str[32] = "111";

sprintf(&str[3],"%d",number);

number = stoll(str);```