import ( "math/big" "testing" ) func TestSetBytes(t *testing.T) { var i big.Int i.SetBytes([]byte{0x01, 0x02, 0x03}) if i.String() != "66051" { t.Error("SetBytes failed to set the correct value") } }
import ( "math/big" "testing" ) func TestSetBytesNegative(t *testing.T) { var i big.Int i.SetBytes([]byte{0xFF, 0xFE, 0xFD}) if i.String() != "-65795" { t.Error("SetBytes failed to set the correct value") } }In this example, we set the value of the big.Int struct using a negative byte slice {0xFF, 0xFE, 0xFD}. As expected, the value of the big.Int struct will be negative. We then check if the value has been set correctly using the String method of the big.Int struct. Package library: math/big