binary

package
v0.0.0-...-14c8dc9 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Dec 13, 2017 License: MIT Imports: 0 Imported by: 0

Documentation

Overview

These are examples of manipulating binary values.

Example (AddBinaryDigits)
package main

import (
	"fmt"
)

func main() {
	data := []bool{false, true, true, false, true, true, false, false}
	var result int
	for _, v := range data {
		result = result << 1
		if v {
			result = result | 1
		}
		fmt.Printf("%d %b\n", result, result)
	}
}
Output:

0 0
1 1
3 11
6 110
13 1101
27 11011
54 110110
108 1101100

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL