Golang : convert rune to integer value
Just a short tutorial on how to convert a rune into integer. Converting rune to integer value can be useful for generating checksum to ensure that the message transmitted is not tempered with.
package main
import "fmt"
func main() {
r1 := rune('你')
i1 := int(r1)
fmt.Println(i1)
fmt.Println(string(i1))
r2 := rune('好')
i2 := int(r2)
fmt.Println(i2)
fmt.Println(string(i2))
r3 := rune('吗')
i3 := int(r3)
fmt.Println(i3)
fmt.Println(string(i3))
// or in a more efficient way
message := []rune{'你', '好', '吗'}
fmt.Println(message)
}
http://play.golang.org/p/J1WHRo4Qtk
Output :
20320
你
22909
好
21527
吗
[20320 22909 21527]
See also : Golang : convert rune to unicode hexadecimal value and back to rune character
By Adam Ng
IF you gain some knowledge or the information here solved your programming problem. Please consider donating to the less fortunate or some charities that you like. Apart from donation, planting trees, volunteering or reducing your carbon footprint will be great too.
Advertisement
Tutorials
+8.9k Android Studio : Simple input textbox and intercept key example
+5k AWS S3 : Prevent Hotlinking policy
+25.3k Golang : dial tcp: too many colons in address
+5.3k Golang : Break string into a slice of characters example
+6k Golang : Squaring elements in array
+15.9k Golang : How to make a file read only and set it to writable again?
+4k Linux/Unix/MacOSX : Find out which application is listening to port 80 or use which IP version
+14.1k Golang : Get current time from the Internet time server(ntp) example
+2.1k Golang : Switch Redis database redis.NewClient
+37.2k Golang : Convert to io.ReadSeeker type
+14.9k Golang : Get file permission
+5.5k Golang : When to use make or new?