Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/three.js/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Go 将包含字符串的[]字节转换为十进制值_Go - Fatal编程技术网

Go 将包含字符串的[]字节转换为十进制值

Go 将包含字符串的[]字节转换为十进制值,go,Go,我试图获取一个字符串,并将字符串中的每个值转换为十进制ASCII值。我首先将字符串转换为[]字节类型,我想获取[]字节的每个元素,并将其转换为十进制ASCII值。这是我的密码: myArray := []byte(password) // convert string into []byte type NumArray := [len(password)]int // create second []int type to store the converted []byte elemen

我试图获取一个字符串,并将字符串中的每个值转换为十进制ASCII值。我首先将字符串转换为[]字节类型,我想获取[]字节的每个元素,并将其转换为十进制ASCII值。这是我的密码:

myArray := []byte(password) // convert string into []byte type
NumArray := [len(password)]int // create second []int type to store the    converted []byte elements
for i := 0; i < len(myArray); i++{
                                /*  I need some help to convert each element in myArray into ASCII decimal value and then store it into 
                                    NumArray.
                                */
fmt.Printf("%d\n", myArray[i]) //prints out what the converted values should be
fmt.Print(NumArray[i]) //prints out the stored converted value for comparison
}
myArray:=[]字节(密码)//将字符串转换为[]字节类型
NumArray:=[len(password)]int//创建第二个[]int类型以存储转换后的[]字节元素
对于i:=0;i

编辑:字符串应该是密码,因此可以包含任何值

您可以将
字节
转换为
int
,如下所示:

NumArray[i] = int(myArray[i])

那么,你已经告诉我们你在做什么了。你有什么问题吗?