Title: Trying to understand how numbers are interpreted in scripts
Post by: Coding Enthusiast on October 01, 2019, 10:54:22 AM
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. 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
Title: Re: Trying to understand how numbers are interpreted in scripts
Post by: odolvlobo on October 02, 2019, 04:05:37 PM
Your values look correct to me. Numbers are little-endian with a sign in the most significant bit. Range | Representation | ================ | ====================== | 0 - 127 | 00 - 7f | 0 - -127 | 80 - ff | 128 - 32767 | 80 00 - ff 7f | -128 - -32767 | 80 80 - ff ff | 32768 - 223-1 | 00 80 00 - ff ff 7f | -32768 - -223+1 | 00 80 80 - ff ff ff | 223 - 231-1 | 00 00 80 00 - ff ff ff 7f | -223 - -231+1 | 00 00 80 80 - ff ff ff ff |
|