lets say i have a long type variable
for exampleim looking for the best algorithm to put 111 for example at the left of the number(Code:long x =43343539839853583;
Code:final result 11143343539839853583)
Printable View
lets say i have a long type variable
for exampleim looking for the best algorithm to put 111 for example at the left of the number(Code:long x =43343539839853583;
Code:final result 11143343539839853583)
So I guess we're assuming that a long is 64 bits? I would just do this: x += 11100000000000000000;
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.
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.
Convert to string, stick "111" at the front, convert back to long?
Like this...
Brewbuck had the right idea...Code:char str[32] = "111";
sprintf(&str[3],"%d",number);
number = stoll(str);