Not logged in.  Login/Logout/Register | List snippets | | Create snippet | Upload image | Upload data

22
LINES

< > BotCompany Repo | #1029522 - compress30BitUint - converts to 1 through 4 bytes, uses big-endian

JavaX fragment (include) [tags: use-pretranspiled]

Libraryless. Click here for Pure Java version (2515L/16K).

static byte[] compress30BitUint(int i) {
  if (i < 0 || i >= 0x40000000) fail("Not a 30 bit uint: " + i);
  if (i < 0x40)
    ret new byte[] { (byte) i };
  if (i < 0x4000)
    ret new byte[] {
      (byte) ((i >> 8) | 0x40),
      (byte) i
    };
  if (i < 0x400000)
    ret new byte[] {
      (byte) ((i >> 16) | 0x80),
      (byte) (i >> 8),
      (byte) i
    };
  ret new byte[] {
    (byte) ((i >> 24) | 0xC0),
    (byte) (i >> 16),
    (byte) (i >> 8),
    (byte) i
  };
}

download  show line numbers  debug dex   

Travelled to 6 computer(s): bhatertpkbcr, mqqgnosmbjvj, pyentgdyhuwx, pzhvpgtvlbxg, tvejysmllsmz, xrpafgyirdlv

No comments. add comment

Snippet ID: #1029522
Snippet name: compress30BitUint - converts to 1 through 4 bytes, uses big-endian
Eternal ID of this version: #1029522/1
Text MD5: 9b7189c50de8efdbf08a3e901d95c166
Transpilation MD5: d6d8eb3b2001c7ee1806ad35165a4ef7
Author: stefan
Category: javax
Type: JavaX fragment (include)
Public (visible to everyone): Yes
Archived (hidden from active list): No
Created/modified: 2020-08-17 16:48:29
Source code size: 500 bytes / 22 lines
Pitched / IR pitched: No / No
Views / Downloads: 30 / 57
Referenced in: [show references]

Formerly at http://tinybrain.de/1029522 & http://1029522.tinybrain.de