Every line of 'golang hex to int' code snippets is scanned for vulnerabilities by our powerful machine learning engine that combs millions of open source libraries, ensuring your Go code is secure.
178 func hexToInt(hexStr string) int { 179 result, _ := strconv.ParseUint(strings.Replace(hexStr, "0x", "", -1), 16, 64) 180 return int(result) 181 }
110 func hex2int(hexStr string) uint64 { 111 // remove 0x suffix if found in the input string 112 cleaned := removeHexSuffix(hexStr) 113 114 // base 16 for hexadecimal 115 result, _ := strconv.ParseUint(cleaned, 16, 64) 116 return result 117 }
243 func hexRunesToInt(b []rune) int { 244 sum := 0 245 for i := 0; i < len(b); i++ { 246 sum += hexToInt(b[i]) << (uint(len(b)-i-1) * 4) 247 } 248 return sum 249 }
187 func parseHexUint(v []byte) (n uint64, err error) { 188 for _, b := range v { 189 n <<= 4 190 switch { 191 case '0' <= b && b <= '9': 192 b = b - '0' 193 case 'a' <= b && b <= 'f': 194 b = b - 'a' + 10 195 case 'A' <= b && b <= 'F': 196 b = b - 'A' + 10 197 default: 198 return 0, errors.New("invalid byte in chunk length") 199 } 200 n |= uint64(b) 201 } 202 return 203 }
75 func wire_intToUint(i int64) uint64 { 76 // signed arithmetic shift 77 return uint64((i >> 63) ^ (i << 1)) 78 }
921 func hexToByte(lo, hi byte) (byte, bool) { 922 h, ok1 := fromHexChar(hi) 923 l, ok2 := fromHexChar(lo) 924 return h<<4 + l, ok1 && ok2 925 }
130 func HexToBigInt(t *testing.T, in string) *big.Int { 131 s := in[2:] 132 b, err := hex.DecodeString(s) 133 require.NoError(t, err) 134 return big.NewInt(0).SetBytes(b) 135 }
61 func Hex2Bin(s string) string { 62 bin, err := strconv.ParseInt(s, 16, 64) 63 if err != nil { 64 log.Fatal(err) 65 } 66 return strconv.FormatInt(bin, 2) 67 }
65 func uintToInt(x uint64) int64 { 66 i := int64(x >> 1) 67 if x&1 != 0 { 68 i = ^i 69 } 70 return i 71 }
149 func Int2HexStr(num int) (hex string) { 150 if num == 0 { 151 return "0" 152 } 153 154 for num > 0 { 155 r := num % 16 156 157 c := "?" 158 if r >= 0 && r <= 9 { 159 c = string(r + '0') 160 } else { 161 c = string(r + 'a' - 10) 162 } 163 hex = c + hex 164 num = num / 16 165 } 166 return hex 167 }