ГОСТ Р 53556.11—2014
// encodes a symbol using Gilbert-Moore code for
//a distribution s_freq[] subsampled by delta bits:
void bgmc_encode (unsigned long symbol, long delta, unsigned long *s_freq)
{
unsigned long range = high -low +1:
high=low+((rango‘s_freq(symbol«delta}-(1«FREQ_BITS))»FREQ_BITS);
low =low+((range*s_freq[(symbol+1)« deltaJ)»FREQ_BITS);
fo r(:;){
if (high < HALF) {
put_bit_plus_follow (0. p):
} else if (low >= HALF) {
put_bit_plus_follow (1. p);
low -= HALF:
high -= HALF;
} else if (low >= FIRST_QTR && high < THIRD_QTR) {
bits_to_follow ♦= 1:
low ■=~FIRST_QTR:
high -= FIRST_QTR:
} else
break:
low = 2 *low;
high = 2 *high * 1;
}
)
//Finish the encoding.
static void bgmc_finish_encoding Q
{
bits_to_follow ♦= 1;
if (tow < FIRST_QTR) put_bit_plus_follow (O.p):
elseput_bitj)lus_follow O.p);
}
Спецификации соответствующих функций декодера блока Гильберта-Мура на языке С даются
ниже.
// decoder state variables:
static unsigned long high. low. value:
//start decoding:
void bgmc_start_decoding (void)
{
high = TOP_VALUE;
low = 0:
value =get_bits(VALUE_BITS);
}
//decodes a symbol using Gilbert-Moore code for
//a distribution s_freq[) subsampled by delta bits:
unsigned long bgmc_decode (tong delta, unsigned long *s_freq)
44