dcrd/math/uint256/example_test.go
Dave Collins 3b8efba395
math/uint256: Prepare v1.0.0.
While the original plan was to keep uint256 as a part of the primitives
module, there has been interest in using the uint256 code now and the
primitives module will not be complete and ready for release for quite
some time.

Also, after further discussion, the general preference is for a separate
module that lives at math/uint256 for this code since the primitives
module will ultimately be squarely aimed at Decred-specific things while
math/uint256 is more generally useful, including many projects outside
of Decred as well.

Thus, this moves the new uint256 package from the internal staging area
to math/uint256 where it will serve as a base for a new math/uint256
module release.

Finally, it updates all relevant paths and package README.md
accordingly.
2021-12-09 17:25:56 -06:00

25 lines
777 B
Go

// Copyright (c) 2021 The Decred developers
// Use of this source code is governed by an ISC
// license that can be found in the LICENSE file.
package uint256_test
import (
"fmt"
"github.com/decred/dcrd/math/uint256"
)
// This example demonstrates calculating the result of dividing a max unsigned
// 256-bit integer by a max unsigned 128-bit integer and outputting that result
// in hex with leading zeros.
func Example_basicUsage() {
// Calculate maxUint256 / maxUint128 and output it in hex with leading zeros.
maxUint128 := new(uint256.Uint256).SetUint64(1).Lsh(128).SubUint64(1)
result := new(uint256.Uint256).Not().Div(maxUint128)
fmt.Printf("result: %064x\n", result)
// Output:
// result: 0000000000000000000000000000000100000000000000000000000000000001
}