我正在尝试获取字符串并将字符串中的每个值转换为十进制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
}
编辑:字符串应该是密码,因此可以包含任何值
答案 0 :(得分:0)
您可以将byte
投射到int
,如下所示:
NumArray[i] = int(myArray[i])