Talk:Variable-length quantity: Difference between revisions

m
 
(3 intermediate revisions by 3 users not shown)
Line 45:
!  0
|-
!
! 2<sup>14</sup>
! 2<sup>13</sup>
! 2<sup>12</sup>
Line 59:
 
i.e. the first byte/octet through would have its high bit set and the last octet would not. --[[User:Paddy3118|Paddy3118]] 17:17, 17 October 2010 (UTC)
 
I agree with Paddy. See also: http://en.wikipedia.org/wiki/File:Uintvar_coding.svg --[[User:Rdm|Rdm]] 23:07, 17 October 2010 (UTC)
 
== Is possible only 9 bytes for full 64 bits ==
 
VLQ uses 7 bits on byte. 7*9 = 63 but fortunately last (==8) byte not need flag; although can have set high bit, is possible to stop counting bytes. It is regarding to one bit.
 
My methods:
 
int number_len(uint64_t x) {
int k = 0;
while (x > 127 && k < 8) {
k++;
x >>= 7;
}
return k + 1;
}
 
void to_seq(uint64_t x, uint8_t *out) {
int k = 0;
while (x > 127 && k < 8) {
out[k] = (uint8_t) x | 128;
k++;
x >>= 7;
}
out[k] = (uint8_t) x;
}
 
uint64_t from_seq(const uint8_t *in) {
uint64_t r = 0;
int n = 0;
while (n < 8 && *in & 128) {
r |= ((uint64_t) (*in & 127)) << (n * 7);
n++;
in++;
}
r |= ((uint64_t) (*in)) << (n * 7);
return r;
}
 
 
[[User:Andrz|Andrz]] ([[User talk:Andrz|talk]]) 19:33, 30 March 2024 (UTC)
2

edits