I lack some kind of fundamental understanding, so do not swear at the question. So, we have an array of bytes (eight-bit binary numbers), even if there are only two elements in it: 00000001, 00000001 Suppose our goal is to get some large number by passing bytes through hash functions, so we got this result. Ok, now just write down these values ββin a row, getting the final large number: 100000001 (zeroes of the first byte removed). In the decimal system, this number is equal to 257. But, if we initially understand our bytes as decimal numbers (two units), then the same (already) decimal number 001001 (three digits per byte) is not equal to 257. after reading bitcoin key info. In fact, the HEX number 17ab (the first two bytes of the key) is not equivalent to the binary representation 1011110101011 (the same two bytes) if we consider these two bytes as a single number . In general, I got confused)
- 2And you do not consider them as a whole. For example, 5 + 7 = 12, and if we consider them as a "whole", then 5 and 7 is 57, and 57 is not equal to 12. That's the whole kitchen. - edem
- "three digits per byte" - why would it? Write down one byte 666. Well, it was nice to show where 17ab is! = 1011110101011b - Vladimir Martyanov
3 answers
Let's start with the end of your question. The last 2 numbers (17ab in hexadecimal number system and 1011110101011 in binary number system) are equal. You can check here .
I think it will be useful for you to refresh information on the positional number systems. See here .
In short, the essence is as follows:
Let b be the base of the number system (CC). b = 2 in binary CC, 10 in decimal, ... Numbers in SS are always less than its base (0 and 1 in binary CC, 0, 1, ..., 9 in decimal CC, 0, 1, ... 9, A, B, C, D, E, F in hex). What value each digit represents in the record of a number is determined by its position. In binary notation 10000001, the first unit gives 1*2^7=128 in the decimal system, and the second unit gives only 1. Often, when working with non-decimal CCs manually, the usual decimal CC is used as an intermediate CC.
The number from your question 100000001, obtained by gluing two units, is translated into decimal CC by the formula: 1*2^8 + 0*2^7 + 0*2^6 +...+ 0*2^1 + 1*2^0 = 1*256 + 1 . That is, because of its position, the first unit turned into 256. If we let go of not 8 digits for each unit, but, say, 4, then we would have: 1*2^4 + 1*2^0 = 1*16 + 1 = 17 . We see that the value introduced by the first unit would change significantly. When you work with decimal numbers, you take from the ceiling the decision to release 3 digits by their entry, and you get 1*10^3 + 1*10^0 = 1*1000 + 1 = 1001 . It seems to me absolutely no wonder that the answers did not coincide.
The fact that the above 2 numbers (17ab in hexadecimal number system and 1011110101011 in binary number system) can be separated-glued, and they remain coincident due to the fact that the base of one system (16) is the base level of another system (2), that is 16 = 2^4 , which leads to the fact that 4 digits from the binary system = 1 digit from hexadecimal. Binary and decimal number systems do not have such a happy property.
- "In fact, the HEX number 17ab (the first two bytes of the key) is not equivalent to the binary representation 1011110101011 (the same two bytes) if we consider these two bytes as a single number ." the author of the question even singled out under what condition these numbers are not equal to each other. - edem
- Thanks for the answer. I have now generated Bitcoin addresses (these are 32-byte numbers, exactly glued together from a certain byte array) and compared them in hex and binary systems. Indeed, to my surprise, arbitrarily taken bytes (more precisely, the numbers derived from them) coincided with each other in different systems, which was not the case when compared with decimal. Now comes understanding. - Mergasov
- More precisely, these are not addresses, but private keys, but not the essence - Mergasov
- @A_Mergasov Not at all. Thanks for the good question. The answer to it clarified and for me the connection between the binary and hexadecimal number systems)) Obviously, the binary and the "hexadecimal" CC, the "quadric" and hexadecimal CC are also related to each other. In general, the trick is that the base of one SS is the degree of another SS. - iramm
This is where the illegal operations begin:
But, if we initially understand our bytes as decimal numbers (two units), then the similarly connected (already) decimal number 001001 (three digits per byte) is absolutely not equal to 257.
The binary representation of a number is one thing, and the decimal representation of a number is another. As an example, two numbers 0 and 1 are "interchangeable", while the remaining numbers have different representations, so the use of such a "transformation" will not give the expected results.
0 | 000 1 | 001 --|---- 2 | 010 3 | 011 4 | 100 ... Look for the answer in positioning the numbers in the representation of a number. For example, the numbers 5 and 7 in the decimal number system are directly 5 and 7, and their sum (arithmetic "connection") is equal to 12. If we apply the "connection" operation to them, which is implied in the question, then we get the number 57. And in the number 57, 5 indicates the number of tens, and 7 indicates the number of units, i.e. 5 miraculously became 50 in the "connection", which is nonsense.
And finally, an example from the natural languages ββof Russian and Georgian: the one who we call "dad" in Georgian will be called "mom" (gr. αααα - dad), and "mom" we do not have "dad". Therefore, do not use illegal transformations for data on which these operations will not make sense.
Numbers, numbers, hexes, letters and other cereal in the head
Numbers do not have a concatenation operation. Only strings.
It just so happened that the numbers are represented in memory as a sequence of bytes. And this sequence is somewhat similar to concatenation. But even she is not her - byte order gives two options - little indian and big indian. Only in one of them can we talk about getting a meaningful result after concatenation.
So.
You have two bytes with a value of 1.
What is concatenation is this sequential entry of numbers .
What is the number here? Byte itself.
How many possible values ββdoes a byte have? 256. This is the basis of the number system.
It turned out 11 in the base number 256 system.
We translate into decimal: 1 * 256 + 1 = 257. Converged.