Bitcoin Forum
April 25, 2024, 06:53:01 PM *
News: Latest Bitcoin Core release: 27.0 [Torrent]
 
   Home   Help Search Login Register More  
Pages: [1]
  Print  
Author Topic: Trying to understand how numbers are interpreted in scripts  (Read 169 times)
Coding Enthusiast (OP)
Legendary
*
Offline Offline

Activity: 1039
Merit: 2783


Bitcoin and C♯ Enthusiast


View Profile WWW
October 01, 2019, 10:54:22 AM
 #1

I'm trying to figure out how numbers are interpreted inside scripts. Could someone check if the following test cases are correct?
"bytes" is only the data part, I'm skipping the size part which would be 0x01, 0x02 and 0x03 for 1, 2 and 3 byte data respectively.
Code:
Integer --- bytes
17       { 17 }
75       { 75 }
76       { 76 }
127      { 127 }
128      { 128, 0 }
129      { 129, 0 }
255      { 255, 0 }
256      { 0, 1 }
32767    { 255, 127 }    // 32767 = 0xff7f = 0b11111111 01111111
32768    { 0, 128, 0 }   // 32768 = 0x0080 = 0b00000000 10000000
32769    { 1, 128, 0 }   // 32769 = 0x0080 = 0b00000001 10000000
65535    { 255, 255, 0 } // 65535 = 0xffff
-2       { 0b10000010 }  // 0b10000010 = 0x82 = 130
-127     { 0b11111111 }  // 0b11111111 = 0xff = 255
-128     { 128, 128 }    // 128 = 0b10000000
-129     { 129, 128 }    // 128 = 0b10000000

Projects List+Suggestion box
Donate: 1Q9s or bc1q
|
|
|
FinderOuter(0.19.1)Ann-git
Denovo(0.7.0)Ann-git
Bitcoin.Net(0.26.0)Ann-git
|
|
|
BitcoinTransactionTool(0.11.0)Ann-git
WatchOnlyBitcoinWallet(3.2.1)Ann-git
SharpPusher(0.12.0)Ann-git
1714071181
Hero Member
*
Offline Offline

Posts: 1714071181

View Profile Personal Message (Offline)

Ignore
1714071181
Reply with quote  #2

1714071181
Report to moderator
1714071181
Hero Member
*
Offline Offline

Posts: 1714071181

View Profile Personal Message (Offline)

Ignore
1714071181
Reply with quote  #2

1714071181
Report to moderator
1714071181
Hero Member
*
Offline Offline

Posts: 1714071181

View Profile Personal Message (Offline)

Ignore
1714071181
Reply with quote  #2

1714071181
Report to moderator
Advertised sites are not endorsed by the Bitcoin Forum. They may be unsafe, untrustworthy, or illegal in your jurisdiction.
1714071181
Hero Member
*
Offline Offline

Posts: 1714071181

View Profile Personal Message (Offline)

Ignore
1714071181
Reply with quote  #2

1714071181
Report to moderator
1714071181
Hero Member
*
Offline Offline

Posts: 1714071181

View Profile Personal Message (Offline)

Ignore
1714071181
Reply with quote  #2

1714071181
Report to moderator
1714071181
Hero Member
*
Offline Offline

Posts: 1714071181

View Profile Personal Message (Offline)

Ignore
1714071181
Reply with quote  #2

1714071181
Report to moderator
odolvlobo
Legendary
*
Offline Offline

Activity: 4298
Merit: 3208



View Profile
October 02, 2019, 04:05:37 PM
Last edit: October 02, 2019, 04:16:56 PM by odolvlobo
Merited by Coding Enthusiast (5), bones261 (4), ABCbits (3)
 #2

Your values look correct to me. Numbers are little-endian with a sign in the most significant bit.

RangeRepresentation
======================================
0 - 12700 - 7f
0 - -12780 - ff
128 - 3276780 00 - ff 7f
-128 - -3276780 80 - ff ff
32768 - 223-100 80 00 - ff ff 7f
-32768 - -223+100 80 80 - ff ff ff
223 - 231-100 00 80 00 - ff ff ff 7f
-223 - -231+100 00 80 80 - ff ff ff ff

Join an anti-signature campaign: Click ignore on the members of signature campaigns.
PGP Fingerprint: 6B6BC26599EC24EF7E29A405EAF050539D0B2925 Signing address: 13GAVJo8YaAuenj6keiEykwxWUZ7jMoSLt
Pages: [1]
  Print  
 
Jump to:  

Powered by MySQL Powered by PHP Powered by SMF 1.1.19 | SMF © 2006-2009, Simple Machines Valid XHTML 1.0! Valid CSS!