Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

math/big: SetBytes allows arbitrary numbers of leading zeros #12751

Closed
hillar opened this issue Sep 25, 2015 · 1 comment
Closed

math/big: SetBytes allows arbitrary numbers of leading zeros #12751

hillar opened this issue Sep 25, 2015 · 1 comment

Comments

@hillar
Copy link

hillar commented Sep 25, 2015

package main

import (
    "fmt"
    "math/big"
)

func main() {

    tmp := new(big.Int)

    b := []byte{0x80}
    fmt.Println("%b",b)
    tmp.SetBytes(b)
    fmt.Println("%+d",tmp)

    b00 := []byte{0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x80}
    fmt.Println("%b",b00)
    tmp.SetBytes(b00)
    fmt.Println("%+d",tmp)

}
%b [128]
%+d 128
%b [0 0 0 0 0 0 0 0 0 0 0 0 128]
%+d 128
@griesemer
Copy link
Contributor

This is working as intended. Keep in mind that SetBytes simply sets x to a valid binary value of a number. The number value is unchanged, no matter how many leading 0's there are.

See also #12231.

@golang golang locked and limited conversation to collaborators Sep 27, 2016
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

No branches or pull requests

3 participants