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.3k Golang : Find relative luminance or color brightness
+5.3k Golang : Customize scanner.Scanner to treat dash as part of identifier
+9.6k Golang : Get all countries currencies code in JSON format
+17.1k Golang : Get input from keyboard
+7k Golang : Normalize email to prevent multiple signups example
+5.9k Golang : Launching your executable inside a console under Linux
+12.1k Golang : Clean formatting/indenting or pretty print JSON result
+10.7k Golang : Interfacing with PayPal's IPN(Instant Payment Notification) example
+5.1k Google : Block or disable caching of your website content
+28.6k Golang : Change a file last modified date and time
+5.6k PHP : Fix Call to undefined function curl_init() error
+23.7k Golang : minus time with Time.Add() or Time.AddDate() functions to calculate past date