Its again basic programming question which I am trying to understand the concept.
I have set of predefined key-values under Pkey and should be of this format
ie the Key is of string type and Value associated with that should be hex ‘0x’. I don’t know how to declare value as hex type .
Questions would be,
How to assign hex value to a key in a dictionary?
If there is a format of type “DS_256” : 124 , my program should read thru the Pkeys range and if it finds 0xValue, skip else convert the non-hex value into an hex and store in an array
ie identify 124 as an integer (since no presence of 0x) and should convert to hex.
I have created a dict with values as shown below.
I want to check if the value of ES_128 is an integer and do some conversion.
Was able to check for the existence of key in the map but how to check if the value of the key is an integer.
(Was just testing the functionality of unicode and resulted in error)
var Pkeys = map[string]int64 {
"ES_128" : 0x00AA,
"PS_256" : 0x00A8,
"DS_256" : 124,
}
type PCdecipher struct {
defTab map[string]int
}
func (pc *PCdecipher) init(Pkeys map[string]int64) {
for _, value := range Pkeys {
if unicode.IsNumber(value) {
fmt.Printf("Found")
}
fmt.Printf(" : 0x0%x",value)
}
}
func main() {
var pc PCdecipher
pc.init(Pkeys)
}
You have defined Pkeys as a map from string to int64, so the values in the map must be int64s.
unicode.IsNumber checks if a rune value (e.g. 'a', '0', '$', etc.) is a numeric code point, but value in your (*PCdecipher).init function is an int64, so it cannot be passed into unicode.IsNumber and you get an error:
./prog.go:21:22: cannot use value (type int64) as type rune in argument to unicode.IsNumber
Go build failed.
I cannot tell what you’re trying to do based on your example. Can you add more description and then maybe someone can give you some suggestions?