Standard library / math/big

big.Int.FillBytes()

Write unsigned magnitude to a fixed-size big-endian buffer with leading zeros. Panic if it does not fit. Expected stdout: '[0 0 1 2]\n'.

Formal Syntax & Structure

go syntaxgo
func (x *Int) FillBytes(buf []byte) []byte

Parameters & Attributes

NameTypeDescription
buf[]byteByte buffer or encoded data, as specified in the method contract.

Return Value

[]byte

Returns the result described above; see the example for the observed behavior.

Working Example

Example Snippetgo
package main
import (  "fmt"  "math/big")
func main() {  fmt.Println(big.NewInt(-258).FillBytes(make([]byte, 4)))}
Go Reference