# package hex
`import "encoding/hex"`
hex包实现了16进制字符表示的编解码。
## Index
* [Variables](#pkg-variables)
* [type InvalidByteError](#InvalidByteError)
* [func (e InvalidByteError) Error() string](#InvalidByteError.Error)
* [func DecodedLen(x int) int](#DecodedLen)
* [func Decode(dst, src []byte) (int, error)](#Decode)
* [func DecodeString(s string) ([]byte, error)](#DecodeString)
* [func EncodedLen(n int) int](#EncodedLen)
* [func Encode(dst, src []byte) int](#Encode)
* [func EncodeToString(src []byte) string](#EncodeToString)
* [func Dump(data []byte) string](#Dump)
* [func Dumper(w io.Writer) io.WriteCloser](#Dumper)
## Variables
```
var ErrLength = errors.New("encoding/hex: odd length hex string")
```
解码一个长度为奇数的切片时,将返回此错误。
## type [InvalidByteError](https://github.com/golang/go/blob/master/src/encoding/hex/hex.go#L37 "View Source")
```
type InvalidByteError byte
```
描述一个hex编码字符串中的非法字符。
### func (InvalidByteError) [Error](https://github.com/golang/go/blob/master/src/encoding/hex/hex.go#L39 "View Source")
```
func (e InvalidByteError) Error() string
```
## func [DecodedLen](https://github.com/golang/go/blob/master/src/encoding/hex/hex.go#L43 "View Source")
```
func DecodedLen(x int) int
```
长度x的编码数据解码后的明文数据的长度
## func [Decode](https://github.com/golang/go/blob/master/src/encoding/hex/hex.go#L49 "View Source")
```
func Decode(dst, src []byte) (int, error)
```
将src解码为DecodedLen(len(src))字节,返回实际写入dst的字节数;如遇到非法字符,返回描述错误的error。
## func [DecodeString](https://github.com/golang/go/blob/master/src/encoding/hex/hex.go#L91 "View Source")
```
func DecodeString(s string) ([]byte, error)
```
返回hex编码的字符串s代表的数据。
## func [EncodedLen](https://github.com/golang/go/blob/master/src/encoding/hex/hex.go#L18 "View Source")
```
func EncodedLen(n int) int
```
长度x的明文数据编码后的编码数据的长度。
## func [Encode](https://github.com/golang/go/blob/master/src/encoding/hex/hex.go#L24 "View Source")
```
func Encode(dst, src []byte) int
```
将src的数据解码为EncodedLen(len(src))字节,返回实际写入dst的字节数:EncodedLen(len(src))。
## func [EncodeToString](https://github.com/golang/go/blob/master/src/encoding/hex/hex.go#L84 "View Source")
```
func EncodeToString(src []byte) string
```
将数据src编码为字符串s。
## func [Dump](https://github.com/golang/go/blob/master/src/encoding/hex/hex.go#L103 "View Source")
```
func Dump(data []byte) string
```
返回给定数据的hex dump格式的字符串,这个字符串与控制台下`hexdump -C`对该数据的输出是一致的。
## func [Dumper](https://github.com/golang/go/blob/master/src/encoding/hex/hex.go#L114 "View Source")
```
func Dumper(w io.Writer) io.WriteCloser
```
返回一个io.WriteCloser接口,将写入的数据的hex dump格式写入w,具体格式为'hexdump -C'。
- 库
- package achive
- package tar
- package zip
- package bufio
- package builtin
- package bytes
- package compress
- package bzip2
- package flate
- package gzip
- package lzw
- package zlib
- package container
- package heap
- package list
- package ring
- package crypto
- package aes
- package cipher
- package des
- package dsa
- package ecdsa
- package elliptic
- package hmac
- package md5
- package rand
- package rc4
- package rsa
- package sha1
- package sha256
- package sha512
- package subtle
- package tls
- package x509
- package pkix
- package database
- package sql
- package driver
- package encoding
- package ascii85
- package asn1
- package base32
- package base64
- package binary
- package csv
- package gob
- package hex
- package json
- package pem
- package xml
- package errors
- package expvar
- package flag
- package fmt
- package go
- package doc
- package format
- package parser
- package printer
- package hash
- package adler32
- package crc32
- package crc64
- package fnv
- package html
- package template
- package image
- package color
- package palette
- package draw
- package gif
- package jpeg
- package png
- package index
- package suffixarray
- package io
- package ioutil
- package log
- package syslog
- package math
- package big
- package cmplx
- package rand
- package mime
- package multipart
- package net
- package http
- package cgi
- package cookiejar
- package fcgi
- package httptest
- package httputil
- package pprof
- package mail
- package rpc
- package jsonrpc
- package smtp
- package textproto
- package url
- package os
- package exec
- package signal
- package user
- package path
- package filepath
- package reflect
- package regexp
- package runtime
- package cgo
- package debug
- package pprof
- package race
- package sort
- package strconv
- package strings
- package sync
- package atomic
- package text
- package scanner
- package tabwriter
- package template
- package time
- package unicode
- package utf16
- package utf8
- package unsafe