From 3287fadac470304a64c440e677daede0025a24da Mon Sep 17 00:00:00 2001 From: Brian M Hamlin Date: Thu, 18 Mar 2021 15:53:52 -0700 Subject: [PATCH] format experimental --- spec/cBITS_provisional_spec.md | 40 +++++++++++++++++----------------- 1 file changed, 20 insertions(+), 20 deletions(-) diff --git a/spec/cBITS_provisional_spec.md b/spec/cBITS_provisional_spec.md index e49f5b5..e0480b9 100644 --- a/spec/cBITS_provisional_spec.md +++ b/spec/cBITS_provisional_spec.md @@ -14,7 +14,6 @@ ## Abstract ## - Notes on Compact BITS Format **Objective**: show BITS (4 byte) compact representation of a uint256 input @@ -25,9 +24,10 @@ Conversion Rules: Take three bytes from uint256, starting with the most-signific +**Example 1** + +convert src to dst (28 bytes of data following four bytes of zero) --- -**Example 1** convert src to dst (28 bytes of data following four bytes of zero) given: 0x000000008cc30f97a647313fe0cad97a647313fe0cad97a647313fe0cad97a64 -------------------------------------------------------------------------- @@ -37,11 +37,10 @@ Step) extract the most-significant three bytes of uint256, store as resInt inCount = 28 (0x1C) -|--------|--------|-----------------|-----------------|-----------------| | resInt | Octets | 140 (0x8C) | 195 (0xC3) | 15 (0x0F) | |--------|--------|-----------------|-----------------|-----------------| | Bits | 1 0 0 0 1 1 0 0 | 1 1 0 0 0 0 1 1 | 0 0 0 0 1 1 1 1 | -|-----------------|-----------------|-----------------|-----------------| + Step) test the high bit of the left-most, non-zero byte of input uint256 ; if set, @@ -50,35 +49,37 @@ Step) test the high bit of the left-most, non-zero byte of input uint256 ; inCount = 29 (0x1D) -|--------|--------|-----------------|-----------------|-----------------| | resInt | Octets | 0 (0x00) | 140 (0x8C) | 195 (0xC3) | |--------|--------|-----------------|-----------------|-----------------| | Bits | 0 0 0 0 0 0 0 0 | 1 0 0 0 1 1 0 0 | 1 1 0 0 0 0 1 1 | -|-----------------|-----------------|-----------------|-----------------| + Step) multiply inCount by 2**24, resulting in a 32bit integer (left shift) inCount shifted left by three (3) bytes -|---------|--------|-----------------|-----------------|-----------------|-----------------| + | inCount | Octets | 29 (0x1D) | 0 (0x00) | 0 (0x00) | 0 (0x00) | |---------|--------|-----------------|-----------------|-----------------|-----------------| | Bits | 0 0 0 1 1 1 0 1 | 0 0 0 0 0 0 0 0 | 0 0 0 0 0 0 0 0 | 0 0 0 0 0 0 0 0 | -|------------------|-----------------|-----------------|-----------------|-----------------| + Step) combine inCount and resInt (logical OR) to make the final Compact BITS (CBITS) -|-------|--------|-----------------|-----------------|-----------------|-----------------| + | CBITS | Octets | 29 (0x1D) | 0 (0x00) | 140 (0x8C) | 195 (0xC3) | |-------|--------|-----------------|-----------------|-----------------|-----------------| | Bits | 0 0 0 1 1 1 0 1 | 0 0 0 0 0 0 0 0 | 1 0 0 0 1 1 0 0 | 1 1 0 0 0 0 1 1 | -|----------------|-----------------|-----------------|-----------------|-----------------| + Expanded Result from compact BITS 0x8cc30000000000000000000000000000000000000000000000000000 --- -**Example 2** convert src to dst (29 bytes of data following three bytes of zero) + +**Example 2** + +convert src to dst (29 bytes of data following three bytes of zero) + given: 0x0000000128a0e4b1fb1fb1fb1fb1fb1fb1fb1fb1fb1fb1fb1fb1fb1fb1fb1fb1 -------------------------------------------------------------------------- @@ -88,11 +89,10 @@ Step) extract the most-significant three bytes of uint256, store as resInt inCount = 29 (0x1D) -|--------|--------|-----------------|-----------------|-----------------| | resInt | Octets | 1 (0x01) | 40 (0x28) | 160 (0xA0) | |--------|--------|-----------------|-----------------|-----------------| | Bits | 0 0 0 0 0 0 0 1 | 0 0 1 0 1 0 0 0 | 1 0 1 0 0 0 0 0 | -|-----------------|-----------------|-----------------|-----------------| + Step) test the high bit of the left-most, non-zero byte of input uint256 ; bit not set @@ -100,19 +100,19 @@ Step) multiply inCount by 2**24, resulting in a 32bit integer (left shift) inCount shifted left by three (3) bytes -|---------|--------|-----------------|-----------------|-----------------|-----------------| + | inCount | Octets | 29 (0x1D) | 0 (0x00) | 0 (0x00) | 0 (0x00) | |---------|--------|-----------------|-----------------|-----------------|-----------------| | Bits | 0 0 0 1 1 1 0 1 | 0 0 0 0 0 0 0 0 | 0 0 0 0 0 0 0 0 | 0 0 0 0 0 0 0 0 | -|------------------|-----------------|-----------------|-----------------|-----------------| + Step) combine inCount and resInt (logical OR) to make the final Compact BITS (CBITS) -+---------+--------+-----------------+-----------------+-----------------+-----------------+ + | inCount | Octets | 29 (0x1D) | 1 (0x01) | 40 (0x28) | 160 (0xA0) | -+---------+--------+-----------------+-----------------+-----------------+-----------------+ +|---------|--------|-----------------|-----------------|-----------------|-----------------| | Bits | 0 0 0 1 1 1 0 1 | 0 0 0 0 0 0 0 1 | 0 0 1 0 1 0 0 0 | 1 0 1 0 0 0 0 0 | -+------------------+-----------------+-----------------+-----------------+-----------------+ + Expanded Result from compact BITS 0x0128A00000000000000000000000000000000000000000000000000000