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

convert int_to_bytes to little endian #564

Merged
merged 2 commits into from
Feb 8, 2019
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 3 additions & 3 deletions specs/core/0_beacon-chain.md
Original file line number Diff line number Diff line change
Expand Up @@ -710,8 +710,8 @@ def shuffle(values: List[Any], seed: Bytes32) -> List[Any]:
if remaining == 1:
break

# Read 3-bytes of `source` as a 24-bit big-endian integer.
sample_from_source = int.from_bytes(source[position:position + rand_bytes], 'big')
# Read 3-bytes of `source` as a 24-bit little-endian integer.
sample_from_source = int.from_bytes(source[position:position + rand_bytes], 'little')
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
sample_from_source = int.from_bytes(source[position:position + rand_bytes], 'little')
sample_from_source = int_to_bytes3(source[position:position + rand_bytes])

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We want to convert bytes-to-int, not int-to-bytes. int.from_bytes is correct, but definitely very pythonic

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Oooh, sorry for the misreading.
And I added bytes_to_int in #576.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

k. will wait on #576 merge and add bytes_to_int here


# Sample values greater than or equal to `sample_max` will cause
# modulo bias when mapped into the `remaining` range.
Expand Down Expand Up @@ -1015,7 +1015,7 @@ def is_power_of_two(value: int) -> bool:

### `int_to_bytes1`, `int_to_bytes2`, ...

`int_to_bytes1(x): return x.to_bytes(1, 'big')`, `int_to_bytes2(x): return x.to_bytes(2, 'big')`, and so on for all integers, particularly 1, 2, 3, 4, 8, 32, 48, 96.
`int_to_bytes1(x): return x.to_bytes(1, 'little')`, `int_to_bytes2(x): return x.to_bytes(2, 'little')`, and so on for all integers, particularly 1, 2, 3, 4, 8, 32, 48, 96.

### `get_effective_balance`

Expand Down