I have a shell script and I do some calculations with DC (1).
I need a number printed with leading zero; I can not find an easy and straightforward way to do this with DC, but it is mentioned in the manpage:
Z stacks off values, calculates the number of digits (Or the number of characters, if this is a string) and pushing that number does not include any leading zeros in the number count for a number, even if they are on the right of the redx point Appear on the side.
What is the simplest and simplest way ...
I know that there is a mingle and one way to accomplish it, and I'm one of them I am walking with happiness. I'm just curious; -)
Give it a try:
Enter:
[lc1 + dsc0nld & gt; B] SB [sddZdscld & gt; BP] Enter a 999 12laxOutput:
000000999:
3laxOutput:
999After the macro ends, the original number is left on the stack Used Registers:
a (macro),b (macro),c (count),d (Points).Explanation:
sets the macro
a , prints the callb and the original number. Points to copy in
sd - registerddz - Save the number - Duplicate original number and count its digit countDSC - calculate the duplicate and register it in thecLD & gt; Load desired digits fromd , if it is more than the count, then the macrobp < / Code> - Print the original numberThe macro
b output zero, unless the number of desired digits is not greater than< Li>
LC1 + - Loadc from the counting register and enlarge itDSC - duplicate count and archive To register this, return <c0n - A newline output without a zerold> gt - the desired load registerd , if it still increased If the count is higher then loop back to run the macrob again, otherwise this collar (macroa )To use arbitrary key character:
[lclkZ + dsclknld & gt; B] SB [sksddZdscld & gt; BP] 99914 [] Lux 999 [ABC] 12 [-] Late --------- ABCIn addition to the other registers, Code> k uses the character (which can actually be more than one):
[XYZ] 6 [DEF] waste dfx 8 [ab] lac ABBABX 4 G [ghjikl] lax ghijklXYZFill strings are fully used, so the length of your expected length is greater than the length of the original string, but two strings The GSA (or is shorter than the length of the integer multiples), so the results may be longer than that.
Comments
Post a Comment