Documentation
¶
Overview ¶
Package hexa provides rudimental hexadecimal conversion functions.
Index ¶
Examples ¶
Constants ¶
const ( X = "X" // common Hash = "#" // cascading style sheets colors Doll = "$" // retro microcomputers U = "U+" // unicode Zero = "0X" // linux and unix C syntax Esc = "\\X" // escape )
Hexadecimal prefix identifiers.
Variables ¶
This section is empty.
Functions ¶
func Parse ¶
Parse converts the provided strings to based unsigned ints. If a string is not a valid integer then the value is -1.
Example ¶
package main import ( "fmt" "github.com/bengarrett/retrotxtgo/cmd/hexa" ) func main() { n := hexa.Parse(16, "0F", "01", "FF", "Z") fmt.Println(n) n = hexa.Parse(10, "15", "1", "255", "abc") fmt.Println(n) }
Output: [15 1 255 -1] [15 1 255 -1]
func Parser ¶
Parser writes the hexadecimal values of the provided decimal strings. Only the results are written and are separated by a space. If a string is not a hexadecimal number then the value is printed as "NaN".
Example ¶
package main import ( "os" "github.com/bengarrett/retrotxtgo/cmd/hexa" ) func main() { _ = hexa.Parser(os.Stdout, 16, "0F", "01", "FF", "Z") }
Output: 15 1 255 NaN
func TrimIdent ¶
TrimIdent trims the hexadecimal prefix identifiers and returns the hexadecimal value as an upper case string.
Example ¶
package main import ( "fmt" "github.com/bengarrett/retrotxtgo/cmd/hexa" ) func main() { // unicode example s := hexa.TrimIdent("U+00A9") fmt.Println(s) // retro hex example s = hexa.TrimIdent("$0F") fmt.Println(s) }
Output: 00A9 0F
func TrimIndents ¶
TrimIndents trims the hexadecimal prefix identifiers and returns the hexadecimal values as upper case strings.
Example ¶
package main import ( "fmt" "github.com/bengarrett/retrotxtgo/cmd/hexa" ) func main() { s := hexa.TrimIndents("U+00A9", "$0F") fmt.Println(s) }
Output: [00A9 0F]
func TrimNCR ¶
TrimNCR trims the numeric character reference prefix and suffix, and returns a decimal integer as a string. If the string is not in NCR syntax, then the original string is returned.
Example ¶
package main import ( "fmt" "github.com/bengarrett/retrotxtgo/cmd/hexa" ) func main() { s := hexa.TrimNCR("©") fmt.Println(s) }
Output: 169
func Writer ¶
Writer the hexadecimal values of the provided decimal strings. If a string is not a hexadecimal number then the value is printed as "invalid".
Example ¶
package main import ( "os" "github.com/bengarrett/retrotxtgo/cmd/hexa" ) func main() { // hexadecimal example _ = hexa.Writer(os.Stdout, 16, "0F", "01", "FF", "Z") // decimal example _ = hexa.Writer(os.Stdout, 10, "15", "1", "255", "abc") }
Output: 0F = 15 01 = 1 FF = 255 Z = invalid 15 = F 1 = 1 255 = FF ABC = invalid