This is from my new compilation OF CS-LIBRARY 2002
enjoy!
+ Code Snippet`CS-LIB 2002 Russel "IronHoof" Hamrick
`-------------------------------------------------------------------
`Conversion Library
`HexVal Converts Hexadecimal to Decimal
`BLS bitshifts a byte left
`BSR bitshifts a byte right
`WriteVLQ Writes a 32 bit variable-Length quantity to a file
`ReadVLQ Reads a 32 bit variable-Length quantity from a file
`-------------------------------------------------------------------
function HexVal(hexnum$)
LENG=LEN(hexnum$):COUNT=1:V2=0
IF LENG=1 THEN GOTO SINGLE:
MORE:
NYBBLE$=mid$(hexnum$,COUNT):V=0
if val(NYBBLE$)>0 then V=Val(NYBBLE$)
if NYBBLE$="A" then V=10
if NYBBLE$="B" then V=11
if NYBBLE$="C" then V=12
if NYBBLE$="D" then V=13
if NYBBLE$="E" then V=14
if NYBBLE$="F" then V=15
EMR=(LENG-COUNT):V2=V2+(V*(16^EMR)):V=0
IF COUNT0 then V=Val(NYBBLE$)
if NYBBLE$="A" then V=10
if NYBBLE$="B" then V=11
if NYBBLE$="C" then V=12
if NYBBLE$="D" then V=13
if NYBBLE$="E" then V=14
if NYBBLE$="F" then V=15
ENDFUNCTION V2+V
function BSL(Initial,ShiftAmount)
ANW=Initial*(2^ShiftAmount)
endfunction ANW
function BSR(Initial,ShiftAmount)
ANW=Initial/(2^ShiftAmount)
endfunction ANW
Function WriteVLQ(Filenum,Value)
BUFFER=Value & hexval("7F")
while value
value=BSR(value,7)
buffer=BSL(buffer,8)
buffer=buffer | ((Value & 127) | 128)
endwhile
INFINITE:
write byte 1,buffer
if (BUFFER & 128) then buffer=BSR(buffer,8) else exitfunction
goto INFINITE:
endfunction
Function ReadVLQ(Filenum)
Value=0
more:
read byte 1,mybyte
Value=Value*128
Mask=mybyte & 127
Value=Value | Mask
if (mybyte & 128)=128 then goto more:
endfunction Value