Skip to content

Commit

Permalink
format experimental
Browse files Browse the repository at this point in the history
  • Loading branch information
Brian M Hamlin committed Mar 18, 2021
1 parent ba3f74b commit 7eff9b8
Showing 1 changed file with 43 additions and 9 deletions.
52 changes: 43 additions & 9 deletions spec/cBITS_provisional_spec.md
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ 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)
convert 256bit hex to cBITS (28 bytes of data following four bytes of zero)

given: 0x000000008cc30f97a647313fe0cad97a647313fe0cad97a647313fe0cad97a64

Expand All @@ -36,7 +36,7 @@ Step) disregard leading zeroes; count the number of data bytes in uint256 input,

Step) extract the most-significant three bytes of uint256, store as resInt

inCount = 28 (0x1C)
<pre>inCount = 28 (0x1C)</pre>

| **Int** | Octets | 140 (0x8C) | 195 (0xC3) | 15 (0x0F) |
|--------|--------|-----------------|-----------------|-----------------|
Expand All @@ -48,7 +48,7 @@ Step) test the high bit of the left-most, non-zero byte of input uint256 ;
shift right resInt one byte (losing precision)
increment the count of pad bytes needed

inCount = 29 (0x1D)
<pre>inCount = 29 (0x1D)</pre>

| **Int** | Octets | 0 (0x00) | 140 (0x8C) | 195 (0xC3) |
|--------|--------|-----------------|-----------------|-----------------|
Expand All @@ -60,17 +60,17 @@ 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) |
| **Int** | 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 |
| | 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 |
|**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
Expand All @@ -80,7 +80,7 @@ Expanded Result from compact BITS

**Example 2**

convert src to dst (29 bytes of data following three bytes of zero)
convert 256bit hex to cBITS (29 bytes of data following three bytes of zero)

given: 0x0000000128a0e4b1fb1fb1fb1fb1fb1fb1fb1fb1fb1fb1fb1fb1fb1fb1fb1fb1

Expand Down Expand Up @@ -121,3 +121,37 @@ Expanded Result from compact BITS

0x0128A00000000000000000000000000000000000000000000000000000


-------------------------------------------------------------


**Example 3a** convert uint64 to dst uint32 to src uint256
Given: 0xFACE00FF00000000

0x000000000000000000000000000000000000000000000000FACE000000000000



**Example 3b** convert 16 bytes to dst uint32, to src uint256
Given: 0xFACE00FF000000000000000000000000

0x00000000000000000000000000000000FACE0000000000000000000000000000


**Example 3c** convert 24 bytes to dst uint32, to src uint256
Given: 0xFACE00FF0000000000000000000000000000000000000000

0x0000000000000000FACE00000000000000000000000000000000000000000000


**Example 3d** convert uint256 to dst uint32, to src uint256
Given: 0xFACE00FF00000000000000000000000000000000000000000000000000000000

0xFACE000000000000000000000000000000000000000000000000000000000000


**Example 4** convert out-of-range dst uint32 to src uint256
Given: 0x2A84FFFF

0x0000000000000000000000000000000000000000000000000000000000000000

0 comments on commit 7eff9b8

Please sign in to comment.