Hi @amelia
First, try to create a working program without constants. This is necessary in order to understand the principle of exporting names starting with a capital letter. Example:
decl/decl.go:
package main
import (
"fmt"
"./decl"
)
func main() {
//var k = decl.Keydata{Bufkeyvalue: 0x5, Bufforeignvalue: 0xA}
k := decl.Keydata{0x5, 0xA}
fmt.Println(k.Bufkeyvalue, k.Bufforeignvalue)
}
If I’m not mistaken, golang does not support constants in structs.
You probably need to consider other types of data in your program
but for fun you can apply the workaround.
decl/decl.go:
@nezabudka
//Most of the variable I declare should be exported. Hence these variables are in UpperCase
//This the default value that HAS to be assigned to the declared variables.
I did go thru some examples in golang.org and there was mention of decoder/encoder.
I used fmt.Printf("%X",baseValues[“DefaultA”]) and the output I got was 10300010002.
My question is " Is there any direct way to store 16 byte hex value to a variable and passing the same hex value to another variable without converting ?
Thanks
Hi @amelia
All data is stored in variables in binary format only. The compiler understands decimal, octal and hexadecimal immediate values and converts them to binary. In what representation to display them it is already your task.
Do you mean that you want to store the string that fmt.Printf prints? If so, then you can use fmt.Sprintf which returns the value as a string instead of printing it to standard output:
Thank you. Yes I want other packages to access the variables (DefaultA…C) with default values as defined inside the map. I tried the command you sent and was able to get the actual value.
I think this is what @nezabudka was talking about: “hex” isn’t a data type; it’s a notation to represent data. The number 4275878552 can be represented in hex as fedcba98 or in binary as 11111110110111001011101010011000, but they’re all the same data type; it’s just in how you show the data.
I don’t mean to split hairs. I’m just mentioning it to see if this is really what you’re looking for ¯\_(ツ)_/¯
If you want to store the hex representations of int64s as strings, then you can do this:
func hexInt64(i int64) string {
return fmt.Sprintf("%X", i)}
}
var n = map[string]string{
"DefaultA": hexInt64(0x0000010300010002),
"DefaultB": hexInt64(0x0000010300020002),
"DefaultC": hexInt64(11),
}