Guest User

Untitled

a guest
Apr 25th, 2018
72
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.57 KB | None | 0 0
  1. package main
  2.  
  3. import (
  4. "encoding/hex"
  5. "fmt"
  6. )
  7.  
  8. func main() {
  9. const sample = "54747A0E4ACF4161D00D244ED341F4329E1E02"
  10.  
  11. bs, _ := hex.DecodeString(sample)
  12.  
  13. fmt.Println(string(decode7bit(bs)))
  14. }
  15.  
  16. func decode7bit(bs []byte) []byte {
  17. bit7s := make([]byte, len(bs)*8/7)
  18.  
  19. for i := range bit7s {
  20. byteStart := (i * 7) / 8
  21. byteEnd := ((i + 1) * 7) / 8
  22. bitStart := (i * 7) % 8
  23. bitEnd := ((i + 1) * 7) % 8
  24.  
  25. low := (bs[byteStart] >> uint8(bitStart)) & 0x7f
  26. high := bs[byteEnd] << uint8(8-bitEnd) >> uint8(8-bitEnd) << uint8(7-bitEnd)
  27.  
  28. bit7s[i] = low | high
  29. }
  30.  
  31. return bit7s
  32. }
Add Comment
Please, Sign In to add comment