Data commit
This commit is contained in:
parent
7387c8f97b
commit
cb5bb5e222
199093 changed files with 3378972 additions and 0 deletions
|
|
@ -0,0 +1,16 @@
|
|||
final RADIX = 7
|
||||
final MASK = 2**RADIX - 1
|
||||
|
||||
def octetify = { n ->
|
||||
def octets = []
|
||||
for (def i = n; i != 0; i >>>= RADIX) {
|
||||
octets << ((byte)((i & MASK) + (octets.empty ? 0 : MASK + 1)))
|
||||
}
|
||||
octets.reverse()
|
||||
}
|
||||
|
||||
def deoctetify = { octets ->
|
||||
octets.inject(0) { long n, octet ->
|
||||
(n << RADIX) + ((int)(octet) & MASK)
|
||||
}
|
||||
}
|
||||
|
|
@ -0,0 +1,8 @@
|
|||
def testNumbers = [ 0x200000, 0x1fffff, 1, 127, 128, 589723405834L ]
|
||||
|
||||
testNumbers.each { a ->
|
||||
def octets = octetify(a)
|
||||
octets.each { printf "0x%02x ", it }; println ()
|
||||
def a1 = deoctetify(octets)
|
||||
assert a1 == a
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue