binToHex

構文
  1. UString = binToHex( bin )
引数
bin
2進数
戻値
16進数に変換した値

プログラム

//////////////////////////////////////////////////
// 【引数】
//   bin : 2進数 
// 【戻値】
//   16進数に変換した値 
//////////////////////////////////////////////////
FUNCTION binToHex(bin)
	HASHTBL bh
	bh["0000"] = "0"; bh["0001"] = "1";
	bh["0010"] = "2"; bh["0011"] = "3";
	bh["0100"] = "4"; bh["0101"] = "5";
	bh["0110"] = "6"; bh["0111"] = "7";
	bh["1000"] = "8"; bh["1001"] = "9";
	bh["1010"] = "a"; bh["1011"] = "b";
	bh["1100"] = "c"; bh["1101"] = "d";
	bh["1110"] = "e"; bh["1111"] = "f";
	len = CEIL(LENGTH(bin) / 4) * 4
	bin = REPLACE(FORMAT(bin, len), " ", "0")
	hex = ""
	FOR n = 1 TO LENGTH(bin) / 4
		str = COPY(bin, n * 4 - 3, 4)
		hex = hex + bh[str]
	NEXT
	RESULT = hex
FEND