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

14
LINES

< > BotCompany Repo | #1011273 - roundUpToPowerOfTwo

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

Libraryless. Click here for Pure Java version (39L/1K).

static int roundUpToPowerOfTwo(int v) {
  v--;
  v |= v >> 1;
  v |= v >> 2;
  v |= v >> 4;
  v |= v >> 8;
  v |= v >> 16;
  ret v+1;
}

static long roundUpToPowerOfTwo(long v) {
  long i = Long.highestOneBit(v);
  ret v > i ? i << 1 : i;
}

download  show line numbers  debug dex   

Travelled to 12 computer(s): aoiabmzegqzx, bhatertpkbcr, cbybwowwnfue, cfunsshuasjs, gwrvuhgaqvyk, ishqpsrjomds, lpdgvwnxivlt, mqqgnosmbjvj, pzhvpgtvlbxg, tslmcundralx, tvejysmllsmz, xrpafgyirdlv

No comments. add comment

Snippet ID: #1011273
Snippet name: roundUpToPowerOfTwo
Eternal ID of this version: #1011273/6
Text MD5: 1ed6df56552a26e7f917c5e1a13182e2
Transpilation MD5: 50db441e64c21ec1f7462c5f7c25b453
Author: stefan
Category: javax
Type: JavaX fragment (include)
Public (visible to everyone): Yes
Archived (hidden from active list): No
Created/modified: 2020-07-31 16:49:28
Source code size: 253 bytes / 14 lines
Pitched / IR pitched: No / No
Views / Downloads: 304 / 322
Version history: 5 change(s)
Referenced in: [show references]

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