Ruud H.G. van Tol skribis:
Just for fun: a way to do dec2hex (and other bases) with procmail.
Limit: (baseType * baseType) - 1 (which is what fits in 2 characters)
(so for base-16, the largest convertable number is 255)
An alternative way, with better limits:
#########################
### File: d2b.procmailrc
#
LOGFILE=$HOME/$_.log
LOGABSTRACT=none
VERBOSE=no
SHELL=/bin/sh
NL="
"
doLog = 1
infinity = 2147483647
dot = "."
baseChars = "0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ"
baseType = 16
decVal = 0
INCLUDERC = $HOME/d2b.inc
decVal = 1
INCLUDERC = $HOME/d2b.inc
decVal = 14
INCLUDERC = $HOME/d2b.inc
decVal = 15
INCLUDERC = $HOME/d2b.inc
decVal = 16
INCLUDERC = $HOME/d2b.inc
decVal = 254
INCLUDERC = $HOME/d2b.inc
decVal = 255
INCLUDERC = $HOME/d2b.inc
decVal = 256
INCLUDERC = $HOME/d2b.inc
decVal = 567
INCLUDERC = $HOME/d2b.inc
decVal = 123456
INCLUDERC = $HOME/d2b.inc
:0
/dev/null
########################
### File: $HOME/d2b.inc
#
:0
* ! tmpVal ?? .
{
tmpVal = $decVal
baseVal = ""
}
:0
*$ -$baseType ^ 0
* 1 ^ 0
*$ $tmpVal ^ 0
{
:0 # DIV basetype
*$ dot ?? $tmpVal ^ 1 > $baseType
{
tmpDiv = $=
:0 # -MUL basetype
*$ $tmpVal ^ 0
*$ dot ?? $tmpDiv ^ 1 < -$baseType
{ }
tmpRem = "$="
tmpChar = "?"
:0
* -1 ^ 0
*$ -$tmpRem ^ 0
*$ $infinity ^ 0
* baseChars ?? 1 ^ 1 ()\/.
{ tmpChar = $MATCH }
baseVal = "$tmpChar$baseVal"
tmpVal = $tmpDiv
INCLUDERC = $_
}
}
:0E
{
tmpRem = $tmpVal
tmpChar = "?"
:0
* -1 ^ 0
*$ -$tmpRem ^ 0
*$ $infinity ^ 0
* baseChars ?? 1 ^ 1 ()\/.
{ tmpChar = $MATCH }
baseVal = "$tmpChar$baseVal"
tmpVal
:0
*$ $doLog ^ 0
{ LOG="base($decVal,$baseType)=$baseVal$NL" }
}
#Test-Log-output for base-16:
base(0,16)=0
base(1,16)=1
base(14,16)=E
base(15,16)=F
base(16,16)=10
base(254,16)=FE
base(255,16)=FF
base(256,16)=100
base(567,16)=237
base(123456,16)=1E240
#Test-Log-output for base-32:
base(0,32)=0
base(1,32)=1
base(14,32)=E
base(15,32)=F
base(16,32)=G
base(254,32)=7U
base(255,32)=7V
base(256,32)=80
base(567,32)=HN
base(123456,32)=3OI0
--
Affijn, Ruud
Roken redt levens.
_______________________________________________
procmail mailing list
procmail(_at_)lists(_dot_)RWTH-Aachen(_dot_)DE
http://MailMan.RWTH-Aachen.DE/mailman/listinfo/procmail