For faster navigation, this Iframe is preloading the Wikiwand page for Elias gamma編碼.

Elias gamma編碼

本條目存在以下問題,請協助改善本條目或在討論頁針對議題發表看法。 此条目也许具备关注度,但需要可靠的来源来加以彰显。(2015年7月29日)请协助補充可靠来源改善这篇条目。 此條目內容疑欠准确,有待查證。 (2022年12月22日)請在讨论页討論問題所在及加以改善,若此條目仍有爭議及准确度欠佳,會被提出存廢討論。 此條目翻譯品質不佳。 (2022年12月22日)翻譯者可能不熟悉中文或原文語言,也可能使用了機器翻譯。請協助翻譯本條目或重新編寫,并注意避免翻译腔的问题。明顯拙劣的翻譯請改掛((d|G13))提交刪除。

以利亞加瑪碼(Elias gamma code)是一種用於正整數之通用編碼。該碼由Peter Elias發明。此編碼常被用於無法事先得知上界之正整數。

編碼

對於待編碼正整數 X≥1:

  1. N=⌊log2 X⌋ ,故 2NX < 2N+1
  2. 輸出 N 個零位元
  3. 接著輸出 X二進位表示。

另一個等價的編碼方式為:

  1. 輸出 N 的一進位表示
  2. 將餘下的 N 個位元接在上述之後。

要對 進行編碼,以利亞戴爾達碼必須使用 位元

以下為一編碼對照表:

二進位表示 加瑪編碼 代表之機率
1 = 20 + 0 1 1 1/2
2 = 21 + 0 1 0 0 1 0 1/8
3 = 21 + 1 1 1 0 1 1 1/8
4 = 22 + 0 1 00 00 1 00 1/32
5 = 22 + 1 1 01 00 1 01 1/32
6 = 22 + 2 1 10 00 1 10 1/32
7 = 22 + 3 1 11 00 1 11 1/32
8 = 23 + 0 1 000 000 1 000 1/128
9 = 23 + 1 1 001 000 1 001 1/128
10 = 23 + 2 1 010 000 1 010 1/128
11 = 23 + 3 1 011 000 1 011 1/128
12 = 23 + 4 1 100 000 1 100 1/128
13 = 23 + 5 1 101 000 1 101 1/128
14 = 23 + 6 1 110 000 1 110 1/128
15 = 23 + 7 1 111 000 1 111 1/128
16 = 24 + 0 1 0000 0000 1 0000 1/512
17 = 24 + 1 1 0001 0000 1 0001 1/512

解碼

以利亞加瑪碼之解碼遵循下列步驟:

  1. 讀取並計數零位元直到第一個一位元出現,假設共有 N 個零位元出現
  2. 從第一個一位元之後,再讀取 N位元,並將之還原成十進位正整數,令之為 M
  3. 最終解碼為 2N+M

用途

以利亞加瑪碼最常見之用途為待編數之上界未知時,或是壓縮小數值較大數值頻繁之資料。以利亞加瑪碼可做為以利亞戴爾達碼之一部分。

一般化

以利亞加瑪碼並不適用於零或負整數。一個一般化的方式是在最左側先加一個一位元,解碼時再行扣掉。另一個方法是在編碼前將所有整數映射至正整數,例如:(0, 1, −1, 2, −2, 3, −3, ...) 對應至 (1, 2, 3, 4, 5, 6, 7, ...)。

參考項目


{{bottomLinkPreText}} {{bottomLinkText}}
Elias gamma編碼
Listen to this article

This browser is not supported by Wikiwand :(
Wikiwand requires a browser with modern capabilities in order to provide you with the best reading experience.
Please download and use one of the following browsers:

This article was just edited, click to reload
This article has been deleted on Wikipedia (Why?)

Back to homepage

Please click Add in the dialog above
Please click Allow in the top-left corner,
then click Install Now in the dialog
Please click Open in the download dialog,
then click Install
Please click the "Downloads" icon in the Safari toolbar, open the first download in the list,
then click Install
{{::$root.activation.text}}

Install Wikiwand

Install on Chrome Install on Firefox
Don't forget to rate us

Tell your friends about Wikiwand!

Gmail Facebook Twitter Link

Enjoying Wikiwand?

Tell your friends and spread the love:
Share on Gmail Share on Facebook Share on Twitter Share on Buffer

Our magic isn't perfect

You can help our automatic cover photo selection by reporting an unsuitable photo.

This photo is visually disturbing This photo is not a good choice

Thank you for helping!


Your input will affect cover photo selection, along with input from other users.

X

Get ready for Wikiwand 2.0 🎉! the new version arrives on September 1st! Don't want to wait?