Go 将包含字符串的[]字节转换为十进制值
我试图获取一个字符串,并将字符串中的每个值转换为十进制ASCII值。我首先将字符串转换为[]字节类型,我想获取[]字节的每个元素,并将其转换为十进制ASCII值。这是我的密码: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
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])
那么,你已经告诉我们你在做什么了。你有什么问题吗?