2

I was looking over the Abe code once again, and came to a stumbling point. I can't understand how this is accurate:

tx['size'] = len(tx['tx'])

Transaction size is simply the length of the raw transaction string? I did not think that 1 character of that string was equal to one byte.

Edit: while tinkering around with this with a simple python command line program, I was able to determine that the block size is actually half of the raw transaction string length. I also found out this:

http://en.wikipedia.org/wiki/Hexadecimal

Each hexadecimal digit represents four binary digits (bits), and the primary use of hexadecimal notation is a human-friendly representation of binary-coded values in computing and digital electronics. One hexadecimal digit represents a nibble, which is half of an octet or byte (8 bits).

Though it still doesn't answer the question, why isn't the size divided by two in the ABE source code?

  • This answer in StackExchange might help: bitcoin.stackexchange.com/a/3011/38618 – MCCCS Jul 14 '16 at 10:41
  • 3
    As you said tx['tx'] is the "raw transaction string" and not it's hexadecimal representation. In this case 1 char does represent 1 byte – Dylan James McGannon Sep 10 '16 at 0:11
  • You are confusing hexadecimal (which is not raw) with a raw string. For example, the raw string "X" can be represented by the hexadecimal string "58". There is no reason to halve the length of the raw transaction string. – David Schwartz Jun 7 '17 at 5:05
1

What you are looking at is the length of a string of hexadecimal characters. When representing data has a hex string, one byte is represented with two characters. However the software does not store the block or transaction data as a hex string, it just stores it as an array of bytes which is later represented as a hex string with each byte having 2 characters. So when the software gets the size of the transaction, it just gets the number of bytes stored in the array, and since each byte corresponds to 2 characters in hexadecimal, when you get the hex string, the hex string will be twice as long as the number of bytes that the block or transaction actually is.

0

Each byte is 8 bits - so in order to display a single byte in hexadecimal, we must see two characters. However when you get the length of a string, you are getting the number of bytes in the string, not its hex equivalent - understand? Therefore it is not necessary to divide by two. If you convert a string into hex, then yes - the hex string will be twice the size, but that is not what you want.

0

One byte is 8 bits and one hexadecimal digit is representing 4 bits, therefore byte lenght is half the lenght of the hex stream. Transaction length is the byte length.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.