Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- package main
- import (
- "encoding/hex"
- "fmt"
- )
- func main() {
- const sample = "54747A0E4ACF4161D00D244ED341F4329E1E02"
- bs, _ := hex.DecodeString(sample)
- fmt.Println(string(decode7bit(bs)))
- }
- func decode7bit(bs []byte) []byte {
- bit7s := make([]byte, len(bs)*8/7)
- for i := range bit7s {
- byteStart := (i * 7) / 8
- byteEnd := ((i + 1) * 7) / 8
- bitStart := (i * 7) % 8
- bitEnd := ((i + 1) * 7) % 8
- low := (bs[byteStart] >> uint8(bitStart)) & 0x7f
- high := bs[byteEnd] << uint8(8-bitEnd) >> uint8(8-bitEnd) << uint8(7-bitEnd)
- bit7s[i] = low | high
- }
- return bit7s
- }
Add Comment
Please, Sign In to add comment