Bitcoin Forum

Bitcoin => Bitcoin Technical Support => Topic started by: BusyAssistant on February 01, 2019, 03:10:58 AM



Title: Really simple question
Post by: BusyAssistant on February 01, 2019, 03:10:58 AM
Hi. This is a dumb question but, how come when I copy a value from bitcoin, e.g. raw hex of a tx, and paste it in a text editor and read the length, it reads 600 chars (bytes), but when I look in the RPC result for size it reads exactly half of that (300) ? Thanks.


Title: Re: Really simple question
Post by: xhomerx10 on February 01, 2019, 03:22:02 AM
First of all, you are mistaken to think that one character equals one byte so your conclusions will be incorrect as well.

One byte is equal to eight bits and it takes two characters to represent one byte in hexadecimal format.

 00 01 02 03 04 05 06 07 08 09 0A 0B 0C 0D 0E 0F 10 11 12 13 14 15 16 17 18 19 1A 1B 1C 1D 1E 1F 20 21 22 23...
 ...F0 F1 F2 F3 F4 F5 F6 F7 F8 F9 FA FB FC FD FE FF

 I'm sure you already knew that but your initial premise threw off your thinking.




Title: Re: Really simple question
Post by: BusyAssistant on February 01, 2019, 03:44:09 AM
Ahhhh damn ok thanks for pointing it out to me, I'm bad at thinking about encoding stuff. Thanks.


Title: Re: Really simple question
Post by: nc50lc on February 01, 2019, 03:50:00 AM
One character is one byte & one byte is 8 bits alright, but it will make him more puzzled by that explanation.
1HEX (00 to FF)=8bits (00000000 to 11111111)=1byte; 1HEX=1Byte.

Where it gone wrong is how the text editor "counts" HEX.
If it was a text editor (example for hex, raw tx), it reads each of the characters as "characters" which is one byte each.

Now, RPC call counts HEX as "HEX" thus each of the two characters were counted as one byte.
That why it's exactly half of the size counted by a text editor like "notepad".


Title: Re: Really simple question
Post by: xhomerx10 on February 01, 2019, 03:53:53 AM
Ahhhh damn ok thanks for pointing it out to me, I'm bad at thinking about encoding stuff. Thanks.

 Not too many are good at thinking about encoding so it's understandable.  Kudos to you for learning.