content_int.go 312 B

1234567891011121314151617181920212223242526
  1. package ber
  2. func encodeUnsignedInteger(i uint64) []byte {
  3. n := uint64Length(i)
  4. out := make([]byte, n)
  5. var j int
  6. for ; n > 0; n-- {
  7. out[j] = (byte(i >> uint((n-1)*8)))
  8. j++
  9. }
  10. return out
  11. }
  12. func uint64Length(i uint64) (numBytes int) {
  13. numBytes = 1
  14. for i > 255 {
  15. numBytes++
  16. i >>= 8
  17. }
  18. return
  19. }