2016-04-02 91 views
0

我想要一個字符串並將字符串中的每個值轉換爲十進制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

你可以施放byteint這樣的:

NumArray[i] = int(myArray[i]) 
相關問題