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)
This is a discussion on easiet way to put digits at the left side of number within the C Programming forums, part of the General Programming Boards category; lets say i have a long type variable for example Code: long x =43343539839853583; im looking for the best algorithm ...
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)
Last edited by cable; 11-04-2011 at 03:10 PM.
So I guess we're assuming that a long is 64 bits? I would just do this: x += 11100000000000000000;
If you understand what you're doing, you're not learning anything.
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.
My homepage
Advice: Take only as directed - If symptoms persist, please see your debugger
Linus Torvalds: "But it clearly is the only right way. The fact that everybody else does it some other way only means that they are wrong"
Convert to string, stick "111" at the front, convert back to long?
Code://try //{ if (a) do { f( b); } while(1); else do { f(!b); } while(1); //}
Like this...
Brewbuck had the right idea...Code:char str[32] = "111"; sprintf(&str[3],"%d",number); number = stoll(str);