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
+3.1k Fix Google Analytics Redundant Hostnames problem
+5.9k Golang : Generate EAN barcode
+4.7k Swift : substringWithRange() function example
+12.9k Golang : Gzip file example
+4.5k Ubuntu : connect() to unix:/var/run/php5-fpm.sock failed (13: Permission denied) while connecting to upstream
+5.6k Swift : Convert (cast) String to Double
+15.8k Golang : Read input from console line
+2.8k Golang : How to solve "too many .rsrc sections" error?
+15.5k Golang : Use regular expression to validate domain name
+15.2k Golang : Use TLS version 1.2 and enforce server security configuration over client
+3k HTTP common errors and their meaning explained
+16.5k Golang : Convert long hexadecimal with strconv.ParseUint example