主题:十六转换成十
wangjieni11
[专家分:0] 发布于 2008-01-05 11:41:00
试编一程序,将不超过5位的十六进制正整数转换成十进制数
回复列表 (共10个回复)
沙发
def [专家分:3380] 发布于 2008-01-06 16:23:00
dim b as string
input b
print val("&h" + b)
end
板凳
QB小猪 [专家分:1200] 发布于 2008-01-16 17:43:00
CLS
INPUT N$
FOR I=LEN(N$) TO 1 STEP -1
A$=MID$(N$,LEN(N$)+1-I,1)
IF ASC(A$)>57 THEN A=ASC(A$)-55 ELSE A=VAL(A$)
X=X+A*16^(I-1)
NEXT I
PRINT X
END
很对哦...
3 楼
QB小猪 [专家分:1200] 发布于 2008-01-16 17:45:00
而且还可以处理超过5位的十六进制正整数呢...
4 楼
强强 [专家分:4740] 发布于 2008-01-21 21:27:00
不知道QB有没有宏,是否可以用宏来做
5 楼
张扬SKY [专家分:20] 发布于 2008-01-23 13:20:00
试编一程序,将不超过5位的十六进制正整数转换成十进制数
do
input a$
loop until LEN(a$)<=5
k=LEN(a$)
for i= 1 to k
b$=mid$(a$,i,1)
IF b$> "9" then
c=asc(b$)-55
ELSE
c=asc(b$)-48
END IF
m=m+c*16^(k-i)
next i
print m
END
话说我们刚有复习过!!
6 楼
hqm1 [专家分:570] 发布于 2008-04-09 19:32:00
CLS
INPUT N$
FOR I = 1 TO LEN(N$)
K$ = MID$(N$, I, 1)
IF ASC(K$) > 97 AND ASC(K$) < 123 THEN PRINT "ERROR!": END
IF ASC(K$) > 64 THEN K = ASC(K$) - 55 ELSE K = ASC(K$) - 48
N = N + K * 16 ^ (LEN(N$) - I)
NEXT I
PRINT N
END
7 楼
世界第一 [专家分:210] 发布于 2008-04-21 13:08:00
cls
input n
c=0
while n>0
a=a+(n mod 10)*16^c
n=n\10
c=c+1
wend
print a
end
请多多指教!
8 楼
科比*布莱恩特 [专家分:40] 发布于 2008-04-29 16:16:00
CLS
INPUT a$
FOR I=LEN(a$) TO 1 STEP -1
n$=MID$(a$,LEN(a$)+1-I,1)
IF ASC(n$)>57 THEN A=ASC(n$)-55 ELSE A=VAL(n$)
X=X+A*16^(I-1)
NEXT I
PRINT X
END
9 楼
FFKK [专家分:1610] 发布于 2009-06-23 17:06:00
DECLARE SUB myprint (n%, v%())
DECLARE SUB mytest (b%, e%, s%, v%())
DIM n, m, k, t, i AS INTEGER
DIM v(34) AS INTEGER
m% = 1
v%(1) = 1
t% = 1
INPUT n%
WHILE m% < n%
t% = t% + 1
v%(t%) = m% + 1
m% = m% + m% + 1
WEND
k% = m% - n%
IF t% <= 2 THEN CALL myprint(t%, v%()) ELSE CALL mytest(3, t%, k%, v%())
SUB myprint (n%, v%())
DIM i AS INTEGER
FOR i% = 1 TO n%
PRINT v%(i%);
NEXT
PRINT
END SUB
SUB mytest (b%, e%, s%, v%())
DIM k, l, x, i AS INTEGER
l% = 1
FOR i% = 1 TO e% - b%
l% = l% * 2
NEXT
k% = s% \ l%
FOR i% = k% TO 0 STEP -1
x% = s% - l% * i%
IF v%(b%) - i% > v%(b% - 1) THEN
v%(b%) = v%(b%) - i%
IF b% = e% THEN CALL myprint(e%, v%()) ELSE CALL mytest(b% + 1, e%, x%, v%())
v%(b%) = v%(b%) + i%
END IF
NEXT
END SUB
10 楼
oqoq [专家分:130] 发布于 2009-06-23 17:33:00
有个函数吧
我来回复