Bitcoin Forum

Bitcoin => Development & Technical Discussion => Topic started by: BlackHatCoiner on December 02, 2020, 09:11:20 AM



Title: [Solved] I get weird results when I try to count the bits of a public key
Post by: BlackHatCoiner on December 02, 2020, 09:11:20 AM
This public key: 0361b5051847a4c00b8fdfe43f9e508099d8375bc84a892e6989733d39bf67c3cc is 66 characters long and it's 258 bits (without the checksum). If I remove the first character, nothing will change to the bits and that's obvious, zero doesn't count. If I remove the second character, though, I get 255 bits.

61b5051847a4c00b8fdfe43f9e508099d8375bc84a892e6989733d39bf67c3cc: 255 bits.

Although, this public key: 03d0f099265fe878d4c93315605ab2f3628be79282187e652e3656a472c27388db which is also 258 bits without the checksum returns me 256 bits when I remove the second character:
d0f099265fe878d4c93315605ab2f3628be79282187e652e3656a472c27388db: 256 bits.

Generating public keys that are 255 bits without the number sign (02 or 03) prevents me from generating mnemonics with them. (Hex to Mnemonic)

Why does this happen? Isn't suppose to be 254 bits without the sign?

I have another example.
Public key: 030244f088c1903ef7ac38f1f35ef8ae6b31fd8c5d4b77185ba6b1c037bdccb3a5 is 258 bits.

0244f088c1903ef7ac38f1f35ef8ae6b31fd8c5d4b77185ba6b1c037bdccb3a5 is 250 bits.


Title: Re: I get weird results when I try to count the bits of a public key
Post by: BlackHatCoiner on December 02, 2020, 01:58:27 PM
I would like to update that I found out what's going on. My conversion from hexadecimal to binary was... throwing away the starting binary zeros (if it had any). This is why I was getting weird results. Because it's random and I didn't know how many zeros one public key may have if we remove the first sign of it. I solved my issue by just converting hex to bin with C#. I used rapidtables.com (https://www.rapidtables.com/convert/number/hex-to-binary.html), but it seems that they remove the starting zeros of a hex by default.

Problem solved!


Title: Re: I get weird results when I try to count the bits of a public key
Post by: odolvlobo on December 03, 2020, 10:29:31 PM
I would like to update that I found out what's going on. My conversion from hexadecimal to binary was... throwing away the starting binary zeros (if it had any). This is why I was getting weird results. Because it's random and I didn't know how many zeros one public key may have if we remove the first sign of it. I solved my issue by just converting hex to bin with C#. I used rapidtables.com (https://www.rapidtables.com/convert/number/hex-to-binary.html), but it seems that they remove the starting zeros of a hex by default.

Problem solved!

I don't know what you are trying to do, but a hexadecimal number has exactly 4 bits per digit.