小结:

1、ASCII编码、GBK编码不是变长编码;

2、数据压缩;

示例:

aabacdab → 00100110111010 → |0|0|10|0|110|111|0|10| → aabacdab

3、变长编码:

符号-位长 映射;

https://en.wikipedia.org/wiki/Variable-length_code

https://baike.baidu.com/item/变长编码表

变长编码表是通过一种评估来源符号出现机率的方法得到的,出现机率高的字母使用较短的编码,反之出现机率低的则使用较长的编码,这便使编码之後的字串的平均长度、期望值降低,从而达到无失真压缩资料的目的。

Variable-length code

From Wikipedia, the free encyclopedia
 
 

Jump to navigationJump to search

This article is about the transmission of data across noisy channels. For the storage of text in computers, see Variable-width encoding.

In coding theory a variable-length code is a code which maps source symbols to a variable number of bits.

Variable-length codes can allow sources to be compressed and decompressed with zero error (lossless data compression) and still be read back symbol by symbol. With the right coding strategy an independent and identically-distributed source may be compressed almost arbitrarily close to its entropy. This is in contrast to fixed length coding methods, for which data compression is only possible for large blocks of data, and any compression beyond the logarithm of the total number of possibilities comes with a finite (though perhaps arbitrarily small) probability of failure.

Some examples of well-known variable-length coding strategies are Huffman codingLempel–Ziv coding and arithmetic coding.

Codes and their extensions[edit]

The extension of a code is the mapping of finite length source sequences to finite length bit strings, that is obtained by concatenating for each symbol of the source sequence the corresponding codeword produced by the original code.

Using terms from formal language theory, the precise mathematical definition is as follows: Let {\displaystyle S} and {\displaystyle T} be two finite sets, called the source and target alphabets, respectively. A code {\displaystyle C:S\to T^{*}} is a total function mapping each symbol from {\displaystyle S} to a sequence of symbols over {\displaystyle T}, and the extension of {\displaystyle C} to a homomorphism of {\displaystyle S^{*}} into {\displaystyle T^{*}}, which naturally maps each sequence of source symbols to a sequence of target symbols, is referred to as its extension.

Classes of variable-length codes[edit]

Variable-length codes can be strictly nested in order of decreasing generality as non-singular codes, uniquely decodable codes and prefix codes. Prefix codes are always uniquely decodable, and these in turn are always non-singular:

Non-singular codes[edit]

A code is non-singular if each source symbol is mapped to a different non-empty bit string, i.e. the mapping from source symbols to bit strings is injective.

  • For example the mapping {\displaystyle M_{1}=\{\,a\mapsto 0,b\mapsto 0,c\mapsto 1\,\}} is not non-singular because both "a" and "b" map to the same bit string "0" ; any extension of this mapping will generate a lossy (non-lossless) coding. Such singular coding may still be useful when some loss of information is acceptable (for example when such code is used in audio or video compression, where a lossy coding becomes equivalent to source quantization).
  • However, the mapping {\displaystyle M_{2}=\{\,a\mapsto 1,b\mapsto 011,c\mapsto 01110,d\mapsto 1110,e\mapsto 10011,f\mapsto 0\}} is non-singular ; its extension will generate a lossless coding, which will be useful for general data transmission (but this feature is not always required). Note that it is not necessary for the non-singular code to be more compact than the source (and in many applications, a larger code is useful, for example as a way to detect and/or recover from encoding or transmission errors, or in security applications to protect a source from undetectable tampering).

Uniquely decodable codes[edit]

A code is uniquely decodable if its extension is non-singular (see above). Whether a given code is uniquely decodable can be decided with the Sardinas–Patterson algorithm.

  • The mapping {\displaystyle M_{3}=\{\,a\mapsto 0,b\mapsto 01,c\mapsto 011\,\}} is uniquely decodable (this can be demonstrated by looking at the follow-set after each target bit string in the map, because each bitstring is terminated as soon as we see a 0 bit which cannot follow any existing code to create a longer valid code in the map, but unambiguously starts a new code).
  • Consider again the code {\displaystyle M_{2}} from the previous section. This code, which is based on an example found in,[1] is not uniquely decodable, since the string 011101110011 can be interpreted as the sequence of codewords 01110 – 1110 – 011, but also as the sequence of codewords 011 – 1 – 011 – 10011. Two possible decodings of this encoded string are thus given by cdb and babe. However, such a code is useful when the set of all possible source symbols is completely known and finite, or when there are restrictions (for example a formal syntax) that determine if source elements of this extension are acceptable. Such restrictions permit the decoding of the original message by checking which of the possible source symbols mapped to the same symbol are valid under those restrictions.

Prefix codes[edit]

Main article: Prefix code

A code is a prefix code if no target bit string in the mapping is a prefix of the target bit string of a different source symbol in the same mapping. This means that symbols can be decoded instantaneously after their entire codeword is received. Other commonly used names for this concept are prefix-free codeinstantaneous code, or context-free code.

  • The example mapping {\displaystyle M_{3}} in the previous paragraph is not a prefix code because we don't know after reading the bit string "0" if it encodes an "a" source symbol, or if it is the prefix of the encodings of the "b" or "c" symbols.
  • An example of a prefix code is shown below.
Symbol Codeword
a 0
b 10
c 110
d 111
Example of encoding and decoding:
aabacdab → 00100110111010 → |0|0|10|0|110|111|0|10| → aabacdab

A special case of prefix codes are block codes. Here all codewords must have the same length. The latter are not very useful in the context of source coding, but often serve as error correcting codes in the context of channel coding.

Another special case of prefix codes are variable-length quantity codes, which encode arbitrarily large integers as a sequence of octets -- i.e., every codeword is a multiple of 8 bits.

Advantages[edit]

The advantage of a variable-length code is that unlikely source symbols can be assigned longer codewords and likely source symbols can be assigned shorter codewords, thus giving a low expected codeword length. For the above example, if the probabilities of (a, b, c, d) were {\displaystyle \textstyle \left({\frac {1}{2}},{\frac {1}{4}},{\frac {1}{8}},{\frac {1}{8}}\right)}, the expected number of bits used to represent a source symbol using the code above would be:

{\displaystyle 1\times {\frac {1}{2}}+2\times {\frac {1}{4}}+3\times {\frac {1}{8}}+3\times {\frac {1}{8}}={\frac {7}{4}}}.

As the entropy of this source is 1.7500 bits per symbol, this code compresses the source as much as possible so that the source can be recovered with zero error.

Notes[edit]

  1. ^ Berstel et al. (2009), Example 2.3.1, p. 63

References[edit]

hide

Lossless
 
Entropy type
Dictionary type
Other types
 
Audio
 
Concepts
Codec parts
 
Image
 
Concepts
Methods
 
Video
 
Concepts
Codec parts
 
Theory

变长编码表 ASCII代码等长编码的更多相关文章

  1. HTML中特殊字符和与之对应的ASCII代码

    ASCII代码是说明了在html中每个特殊字符的属性以及字符的简要说明.在使用html时,如何把ASCII代码添加到网页中.例如版权符号'©'在html中可以通过 "©"来显示. ...

  2. Java 控制台输入数字 输出乘法表(代码练习)

    最近,回忆了一些刚学习Java时经常练习的一些小练习题.感觉还是蛮有趣的,在回顾时想起好多学习时的经历和坎坷,一道小小的练习题要研究半天,珍重过往,直面未来.下面贡献代码,Java 控制台输入数字 输 ...

  3. 基于HTML5手机登录注册表单代码

    分享一款基于HTML5手机登录注册表单代码.这是一款鼠标点击注册登录按钮弹出表单,适合移动端使用.效果图如下: 在线预览   源码下载 实现的代码. html代码: <div class=&qu ...

  4. 基于jQuery会员中心安全修改表单代码

    基于jQuery会员中心安全修改表单代码.这是一款登录密码,交易密码,手机号码,实名认证,电子邮箱,安全设置表单,会员表单等设置代码.效果图如下: 在线预览   源码下载 实现的代码. html代码: ...

  5. 常用字符与ASCII代码对照表

    常用字符与ASCII代码对照表 为了便于查询,以下列出ASCII码表:第128-255号为扩展字符(不常用) ASCII码 键盘 ASCII 码 键盘 ASCII 码 键盘 ASCII 码 键盘 27 ...

  6. [转]常用字符与ASCII代码对照表

    常用字符与ASCII代码对照表 为了便于查询,以下列出ASCII码表:第128-255号为扩展字符(不常用) ASCII码 键盘 ASCII 码 键盘 ASCII 码 键盘 ASCII 码 键盘 27 ...

  7. 基于jQuery商品分类选择提交表单代码

    分享一款基于jQuery商品分类选择提交表单代码.这是一款基于jQuery实现的商品信息选择列表表单提交代码. 在线预览   源码下载 实现的代码: <div class="yList ...

  8. Cheat Engine 作弊表框架代码

    打开游戏 打开自动汇编 扫描的所有过程,这里就省略了 引用作弊表框架代码 查找使阳光减少的地址 拷贝这个地址 添加到自动汇编脚本里,并添加汇编指令 分配到当前作弊表 生成自动汇编脚本 进行激活测试 可 ...

  9. CSS样式表初始化代码

    CSS为什么要初始化?建站老手都知道,这是为了考虑到浏览器的兼容问题,其实不同浏览器对有些标签的默认值是不同的,如果没对CSS初始化往往会出现浏览器之间的页面差异.当然,初始化样式会对SEO有一定的影 ...

随机推荐

  1. 关于java线程、进程的一些问题

    1.多核硬件上,java中同一个进程的多个线程可以运行在不同的CPU上么? 应该是可以的,在eclipse上面跑一个模拟程序,一个死循环的线程可以占用系统(4核,Win7)%的CPU,4个这样的线程刚 ...

  2. Socket网络编程--简单Web服务器(5)

    这一小节我们将实现服务器对get和post的请求进行对cgi程序的调用.对于web服务器以前的章节已经实现了对get和post请求的调用接口,接下来给出对应接口的实现. int WebServer:: ...

  3. java框架篇---hibernate入门

    Hibernate是一个开放源代码的对象关系映射框架,它对JDBC进行了非常轻量级的对象封装,使得Java程序员可以随心所欲的使用对象编程思维来操纵数据库. Hibernate可以应用在任何使用JDB ...

  4. 国内AR行业现状研究之百度的AR

    AR(Augmented Reality),中文翻译增强现实.按我原来的知识体系,VR/AR的技术构成是相同的,只是追求的方向不同.VR是虚拟笼罩现实.让虚拟就是现实:AR则让虚拟进入现实.二者最终看 ...

  5. 关于指针*前后const代表的意思——记住一个口诀“左内右本”

    记住一个口诀“左内右本”:const出现在*的左边,则说明指针所指向的内容是常量const出现在*的右边,则说明指针本身是常量如果*左右两边都出现const,那么说明指针本事是常量,它所指向的内容也是 ...

  6. [转]如何通过 App Store 审核(iOS 开发者经验分享)

    CocoaChina交流社区曾经发起一个主题讨论,关于iOS开发者遇到审核失败的原因及解决办法的,有价值的回复内容如下: wubo9935 App中设计的图标与Apple原生图标类似,Apple原生图 ...

  7. 如何使用ABBYY FineReader 12将JPEG文件转换成Word文档

    日常工作中处理JPEG格式的图像文件时,有时需要转换成Word文档进行编辑,市场上应用而生了很多转换工具,相信不少人听说过OCR(光学字符识别)软件,可以用来转换图像文件,而在OCR软件中, ABBY ...

  8. Mac和Windows中常见中文字体的英文名称

    我们在给HTML元素设置字体的时候经常会有类似 “ font-family:"微软雅黑", "黑体" ” 这样的写法,尤其是在使用Dreamweaver.Apt ...

  9. Kafka 1.1新功能:数据的路径间迁移

    经常有小伙伴有这样的疑问:为什么线上Kafka机器各个磁盘间的占用不均匀,经常出现“一边倒”的情形? 这是因为Kafka只保证分区数量在各个磁盘上均匀分布,但它无法知晓每个分区实际占用空间,故很有可能 ...

  10. redis aof和rdb区别

    转自https://blog.csdn.net/m0_38110132/article/details/76906422 1.前言 最近在项目中使用到Redis做缓存,方便多个业务进程之间共享数据.由 ...