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
+6.8k Golang : Sort words with first uppercase letter
+18.9k Golang : Count number of digits from given integer value
+15.7k Golang : How to tell if a file is compressed either gzip or zip ?
+3.5k Javascript : How to show different content with noscript?
+7.8k Golang : Capture text return from exec function example
+6.4k Javascript : Push notifications to browser with Push.js
+25.1k Golang : Calculate future date with time.Add() function
+6.3k Golang : Check to see if *File is a file or directory
+15.5k Golang : Merge video(OpenCV) and audio(PortAudio) into a mp4 file
+7.7k nginx: [emerg] bind() to 0.0.0.0:80 failed (98: Address already in use)
+17k Golang : Find IP address from string
+4.1k Linux/Unix/MacOSX : Find out which application is listening to port 80 or use which IP version