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

Why length in bits instead of bytes in Human Readable CIDs? #19

Open
ivan386 opened this issue Apr 3, 2018 · 1 comment
Open

Why length in bits instead of bytes in Human Readable CIDs? #19

ivan386 opened this issue Apr 3, 2018 · 1 comment

Comments

@ivan386
Copy link

ivan386 commented Apr 3, 2018

# example CID
zb2rhe5P4gXftAwvA4eXQ5HJwsER2owDyS9sKaQRRVQPn93bA
# corresponding human readable CID
base58btc - cidv1 - raw - sha2-256-256-6e6ff7950a36187a801613426e858dce686cd7d7e3c0fc42ee0330072d245c95

In multihash length in bytes

Format

<varint hash function code><varint digest size in bytes><hash function output>

Binary example (only 4 bytes for simplicity):

fn code  dig size hash digest
-------- -------- ------------------------------------
00010001 00000100 101101100 11111000 01011100 10110101
sha1     4 bytes  4 byte sha1 digest
@Stebalien
Copy link
Member

In the multihash binary format, we use bytes for efficiency. We haven't actually defined a human readable multihash format. If we had, we would have used bits as most hashes are talked about in terms of bit length (160, 256, 384, 512, etc.) not byte length (20, 32, 48, 64, etc.).

Which is why we use bits here.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants