给你一个!
任意进制转换
const MinBase = 2
MaxBase = 36
function NumToStr (num, len, base: Integer
neg: Boolean
fill: char): string
// num = 要转换的数
// len = 生成字符串的最小长度
// base = 进制数 2 = 二进制
// neg = 是否允许负数
// fill = 填充字符用于补满字符串长度//
// 用法:
// NumToStr (45, 8, 2, false, ''0'') > ''00101101''
// NumToStr (45, 4, 8, false, ''0'') > ''0055''
// NumToStr (45, 4, 10, false, '' '') > '' 45''
// NumToStr (45, 4, 16, false, ''0'') > ''002D''
// NumToStr (45, 0, 36, false, '' '') > ''19''
//
var s: string
digit: Integer
begin
num:= ABS (num)
if ((base >= MinBase) and (base <= MaxBase)) then begin
s:= ''''
repeat
digit:= num mod base
if digit < 10 then Insert (CHR (digit + 48), s, 1)
else Insert (CHR (digit + 55), s, 1)
num:= num div base
until num = 0
if neg then Insert (''-'', s, 1)
while Length(s) < len do Insert (fill, s, 1)
end
Result:= s
end