Coder Social home page Coder Social logo

bitio's People

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

bitio's Issues

Use uint8 rather than byte

I was confused for a second with n being of type byte. Using uint8 might help to distinguish between unsigned integer vs. a byte value.

func (r *Reader) ReadBits(n byte) (u uint64, err error)
would become
func (r *Reader) ReadBits(n uint8) (u uint64, err error)

Is the bit order reversed?

       H         L
       ↓         ↓ 
0x0A = 0b0000_1010

when w.WriteBits(0x0A, 7), get 0001_0100 .

0000_1010 << (8 - 1) = 0001_0100

package main

import (
	"bytes"
	"fmt"

	"github.com/icza/bitio"
)

func main() {
	buffer := &bytes.Buffer{}
	w := bitio.NewWriter(buffer)
	w.WriteBits(0x0A, 7)
	w.Align()
	fmt.Printf("%08b\n", 0x0A)
	fmt.Printf("%08b\n", buffer.Bytes()[0])
	fmt.Printf("%02X\n", buffer.Bytes()[0])

	// Output:
	// 00001010
	// 00010100
	// 14
}

Flush to output to file

How can I call Flush so that my file gets written?

func WriteToFile() {
	// open output file
	fo, err := os.Create("output.txt")
	if err != nil {
		panic(err)
	}
	// close fo on exit and check for its returned error
	defer func() {
		if err := fo.Close(); err != nil {
			panic(err)
		}
	}()
	// make a write buffer
	w := bitio.NewWriter(fo)
	err = w.WriteBits(0x08, 8)
	if err != nil {
		panic(err)
	}
//????
	//w.Flush()
	err = w.Close()
	if err != nil {
		panic(err)
	}
}

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.