人妖在线一区,国产日韩欧美一区二区综合在线,国产啪精品视频网站免费,欧美内射深插日本少妇

新聞動(dòng)態(tài)

Python 中 Elias Delta 編碼詳情

發(fā)布日期:2021-12-10 21:57 | 文章來源:gibhub

語法:

Elias Delta Encoding(X)= Elias Gamma encoding (1+floor(log2(X)) + Binary representation of X without MSB.

1、分步實(shí)施

首先,在為 Elias Delta 編碼編寫代碼之前,我們將實(shí)現(xiàn) Elias delta 編碼。

第1步:

  • 從數(shù)學(xué)庫導(dǎo)入 logfloor 函數(shù)以執(zhí)行對數(shù)運(yùn)算。
  • 從用戶獲取輸入 k 以在 Elias Gamma 中進(jìn)行編碼。
  • 使用數(shù)學(xué)模塊中的 floor log 函數(shù),找到 1+floor(log2(X) 并將其存儲(chǔ)在變量 N 中。
  • 使用 (N-1)*'0'+'1' 找到 N 的一元編碼,它為我們提供了一個(gè)二進(jìn)制字符串,其中最低有效位為 '1',其余最高有效位為 N-1 個(gè)'0'。

示例: 某些值的 Elias Gamma 編碼

def EliasGammaEncode(k):
 if (k == 0):
  return '0'
 N = 1 + floor(log(k, 2))
 Unary = (N-1)*'0'+'1'
 return Unary + Binary_Representation_Without_MSB(k)

第2步:

  • 創(chuàng)建一個(gè)函數(shù),該函數(shù)接受輸入 X 并給出結(jié)果作為 X 的二進(jìn)制表示,沒有 MSB
  • 使用“{0:b}”.format(k) 找到 k 的二進(jìn)制等效項(xiàng)并將其存儲(chǔ)在名為 binary 的變量中。
  1. 前綴零僅指定應(yīng)使用 format() 的哪個(gè)參數(shù)來填充 {}。
  2. b 指定參數(shù)應(yīng)轉(zhuǎn)換為二進(jìn)制形式。
  • 返回字符串 binary[1:] ,它是 X 的二進(jìn)制表示,沒有 MSB。

示例: 不帶 MSB 的二進(jìn)制表示

def Binary_Representation_Without_MSB(x):
 binary = "{0:b}".format(int(x))
 binary_without_MSB = binary[1:]
 return binary_without_MSB

現(xiàn)在我們要為 Elias Delta Encoding 編寫代碼

第3步:

  • 從用戶獲取輸入 k 以在 Elias Delta 中進(jìn)行編碼。
  • 使用數(shù)學(xué)模塊中的 floor log 函數(shù),找到 1+floor(log2(k) 。
  • 1+floor(log2(k) 的結(jié)果傳遞給 Elias Gamma 編碼函數(shù)。

示例:某些值的 Elias Delta 編碼

def EliasDeltaEncode(x):
 Gamma = EliasGammaEncode(1 + floor(log(k, 2)))
 binary_without_MSB = Binary_Representation_Without_MSB(k)
 return Gamma+binary_without_MSB

k = int(input('Enter a number to encode in Elias Delta: '))
print(EliasDeltaEncode(k))

第4步:

  • 得到不帶 MSB 的 k 的 Elias Gamma 編碼和二進(jìn)制表示的結(jié)果
  • 連接兩個(gè)結(jié)果并在控制臺(tái)上打印它們

為某些整數(shù)值生成 Elias Delta 編碼的完整代碼

from math import log
from math import floor
def Binary_Representation_Without_MSB(x):
 binary = "{0:b}".format(int(x))
 binary_without_MSB = binary[1:]
 return binary_without_MSB
def EliasGammaEncode(k):
 if (k == 0):
  return '0'
 N = 1 + floor(log(k, 2))
 Unary = (N-1)*'0'+'1'
 return Unary + Binary_Representation_Without_MSB(k)
def EliasDeltaEncode(x):
 Gamma = EliasGammaEncode(1 + floor(log(k, 2)))
 binary_without_MSB = Binary_Representation_Without_MSB(k)
 return Gamma+binary_without_MSB
k = 14
print(EliasDeltaEncode(k))

輸出:

00100110

到此這篇關(guān)于Python 中 Elias Delta 編碼詳情的文章就介紹到這了,更多相關(guān)Python 中 Elias Delta 編碼內(nèi)容請搜索本站以前的文章或繼續(xù)瀏覽下面的相關(guān)文章希望大家以后多多支持本站!

版權(quán)聲明:本站文章來源標(biāo)注為YINGSOO的內(nèi)容版權(quán)均為本站所有,歡迎引用、轉(zhuǎn)載,請保持原文完整并注明來源及原文鏈接。禁止復(fù)制或仿造本網(wǎng)站,禁止在非www.sddonglingsh.com所屬的服務(wù)器上建立鏡像,否則將依法追究法律責(zé)任。本站部分內(nèi)容來源于網(wǎng)友推薦、互聯(lián)網(wǎng)收集整理而來,僅供學(xué)習(xí)參考,不代表本站立場,如有內(nèi)容涉嫌侵權(quán),請聯(lián)系alex-e#qq.com處理。

相關(guān)文章

實(shí)時(shí)開通

自選配置、實(shí)時(shí)開通

免備案

全球線路精選!

全天候客戶服務(wù)

7x24全年不間斷在線

專屬顧問服務(wù)

1對1客戶咨詢顧問

在線
客服

在線客服:7*24小時(shí)在線

客服
熱線

400-630-3752
7*24小時(shí)客服服務(wù)熱線

關(guān)注
微信

關(guān)注官方微信
頂部