Jump to content

Rice coding: Difference between revisions

→‎{{header|Wren}}: Updated in line with Julia and also added basic codings for k= 4.
m (→‎{{header|Julia}}: fix padding)
(→‎{{header|Wren}}: Updated in line with Julia and also added basic codings for k= 4.)
Line 156:
var digits = Int.digits(r, 2)
var dc = digits.count
if (dc < k + 1) res.addAll([0] * (k + 1 - dc))
res.addAll(digits)
return res
Line 187:
var res = Rice.encodeEx(i, 2)
Fmt.print("$3d -> $-9s -> $ d", i, res.join(""), Rice.decodeEx(res, 2))
}
 
System.print("\nBasic Rice coding (k == 4):")
for (i in 0..17) {
var res = Rice.encode(i, 4)
Fmt.print("$2d -> $-6s -> $d", i, res.join(""), Rice.decode(res, 4))
}</syntaxhighlight>
 
Line 226 ⟶ 232:
9 -> 11110010 -> 9
10 -> 111110000 -> 10
 
Basic Rice coding (k == 4):
0 -> 00000 -> 0
1 -> 00001 -> 1
2 -> 00010 -> 2
3 -> 00011 -> 3
4 -> 00100 -> 4
5 -> 00101 -> 5
6 -> 00110 -> 6
7 -> 00111 -> 7
8 -> 01000 -> 8
9 -> 01001 -> 9
10 -> 01010 -> 10
11 -> 01011 -> 11
12 -> 01100 -> 12
13 -> 01101 -> 13
14 -> 01110 -> 14
15 -> 01111 -> 15
16 -> 100000 -> 16
17 -> 100001 -> 17
</pre>
9,485

edits

Cookies help us deliver our services. By using our services, you agree to our use of cookies.