vb6 - Converting VERY large number to a hex string -
public function mymod(a double, b double) double mymod = - int(a / b) * b end function
this code doesn't work doesn't correctly show remainder able calculate hex.
correct : 10009335357561071 / 16 = 62558345984756.69 vb6 mymod returns 0 instead of valid remainder.
i have been unable figure out how convert such large value hex string?
i able code myself. because of vb6 limitations of size of number, had go in different ways. needed able covert large whole numbers binary , hexadecimal.
this code, there 3 functions can use. 1) decimal 2 hex 2) binary hex 3) decimal 2 binary
the code works , gives me correct returns large numbers.
public function dec2hex(dec string) string dec2hex = binary2hex(dec2bin(dec)) end function public function binary2hex(binary string, optional pos long = 0) string dim tic long dim sz long dim x long dim z long dim @ long dim hx long dim hxb string dim xstart long dim xstop long hxb = vbnullstring if instrb(binary, " ") <> 0 binary = replace(binary, " ", "") sz = len(binary) xstart = sz xstop = xstart - 3 @ = 0 hx = 0 if xstop < 1 xstop = 1 x = xstart xstop step -1 @ = @ + 1 if ascb(mid$(binary, x, 1)) = 49 select case @ case 1: hx = hx + 1 case 2: hx = hx + 2 case 3: hx = hx + 4 case 4: hx = hx + 8 end select end if next x hxb = digit2hex(cstr(hx)) + hxb if x <= 1 exit xstart = x xstop = xstart - 3 loop binary2hex = hxb end function private function digit2hex(digit string) string select case digit case "0": digit2hex = "0" case "1": digit2hex = "1" case "2": digit2hex = "2" case "3": digit2hex = "3" case "4": digit2hex = "4" case "5": digit2hex = "5" case "6": digit2hex = "6" case "7": digit2hex = "7" case "8": digit2hex = "8" case "9": digit2hex = "9" case "10": digit2hex = "a" case "11": digit2hex = "b" case "12": digit2hex = "c" case "13": digit2hex = "d" case "14": digit2hex = "e" case "15": digit2hex = "f" case else: digit2hex = vbnullstring end select end function public function dec2bin(dec string) string dim bin string dim var variant dim p long dim tmp string bin = vbnullstring tmp = dec bin = iif(iseven(tmp), "0", "1") + bin var = cdec(tmp) var = var / 2 tmp = cstr(var) p = instr(tmp, ".") if p > 0 tmp = mid(tmp, 1, p - 1) if len(tmp) = 1 if clng(tmp) = 0 exit end if loop dec2bin = bin end function public function iseven(dec string) boolean dim oe long dim mydec variant oe = clng(right$(cstr(dec), 1)) iseven = (oe = 0 or oe = 2 or oe = 4 or oe = 6 or oe = 8) end function
Comments
Post a Comment