[Question]
  [
Your task is to, given an unsigned integer `n`, find the largest number which can be created by removing a single byte (8 consecutive bits) of data.
---
## Example
Given the number `7831`, we first convert it to binary (removing any leading zeroes):
```
1111010010111
```
We then find the consecutive group of 8 bits which, when removed, will yield the largest new result. In this case, there are 3 solutions, shown below
```
1111010010111
  ^      ^       
   ^      ^
    ^      ^
```
Removing this any of these yields `11111`, which we then convert back to its decimal value `31` for the answer.
---
## Test Cases
```
256        ->   1
999        ->   3
7831       ->   31
131585     ->   515
7854621    ->   31261
4294967295 ->   16777215 (if your language can handle 32 bit integers)
```
---
## Rules
* It is guaranteed that the bit length of `n` will be larger than 8.
* Your solution should theoretically work for any bit length of `n` larger than 8, but in practice, needs only work for integers **255 < n < 216**
* Input/Output should be in decimal.
* You may submit a full program or a function.
* This is [code-golf](/questions/tagged/code-golf "show questions tagged 'code-golf'"), so the shortest program (in bytes) wins!
  
[Answer]
# [Jelly](https://github.com/DennisMitchell/jelly), 6 [bytes](https://github.com/DennisMitchell/jelly/wiki/Code-page)
```
BḄ-8ƤṀ
```
A monadic link taking a number and returning a number.
**[Try it online!](https://tio.run/##y0rNyan8/9/p4Y4WXYtjSx7ubPj//7@5hamJmZEhAA "Jelly – Try It Online")**
### How?
Uses a nice [quick](https://github.com/DennisMitchell/jelly/wiki/Quicks), `Ƥ`, developed by [miles](https://codegolf.stackexchange.com/users/6710/miles)...
```
BḄ-8ƤṀ - Link: number
B      - convert to a binary list
    Ƥ  - for loop over some slices to be determined...
  -8   - this is a negative nilad, therefore: use overlapping outfixes of length 8
       -   (exactly what the specification asks us to inspect)
 Ḅ     -   convert from a binary list to an integer (vectorises)
     Ṁ - maximum
```
[Answer]
# [J](http://jsoftware.com/), 12 bytes
```
[:>./8#.\.#:
```
[Try it online!](https://tio.run/##y/r/P81WTyHayk5P30JZL0ZP2ep/anJGvkKagpGpGReUaWlpCWMaGhuaWpjCeOYWpiZmRoYwromRpYmlmbmRpanCfwA "J – Try It Online")
```
          #:     to binary
     8  \.       remove consecutive groups of eight
      #.         convert each result to decimal
  >./            maximum
[:               do nothing, this lets me avoid parentheses
```
[Answer]
# [Python 2](https://docs.python.org/2/), 41 bytes
```
f=lambda n:n>>8and max(n>>8,2*f(n/2)+n%2)
```
[Try it online!](https://tio.run/##FYxBCoMwEADP7Sv2UkjqgmTNxqygHyk9pEioUFcRD@3rU73NzGHW3/5elErJ/SfNrzGBdjoMMekIc/qak5Hu2WhNttIb2ZKXDRQmhQdxQBARhDY2DsE1jiOfxj7QETyJl9CS8LO7XtZt0h2MIhw7a8sf "Python 2 – Try It Online")
[Answer]
## JavaScript (ES6), 54 bytes
```
f=(n,v=n>>8,b=1,m=0)=>b>v?m:f(n,(v^n)&b^v,b+b,v>m?v:m)
```
```
<input type=number min=256 max=2147483647 oninput=o.textContent=f(this.value)><pre id=o>
```
Works up to 2\*\*31-1. Because someone asked for a bit-twiddling answer...
[Answer]
# [Pyth](https://pyth.readthedocs.io), 21 bytes
```
L&K.>b8eS,K+*2y/b2%b2
```
This is a recursive function (must be called with `y`, or see the link).
**[Try it here!](https://pyth.herokuapp.com/?code=L%26K.%3Eb8eS%2CK%2B%2a2y%2Fb2%25b2%3By&input=7831&test_suite=1&test_suite_input=7831%0A131585&debug=0)**
[Answer]
# Mathematica, 69 bytes
```
Max@Array[Drop[#&@@s,#;;#+7]~FromDigits~2&,Last[s=#~RealDigits~2]-7]&
```
[Try it online!](https://tio.run/##y00syUjNTSzJTE78n6Zgq/DfN7HCwbGoKLEy2qUovyBaWc3BoVhH2dpaWds8ts6tKD/XJTM9s6S4zkhNxyexuCS62Fa5Lig1MQcmHKtrHqv2P6AoM6/EIS3axMjSxNLM3MjSNPY/AA "Wolfram Language (Mathematica) – Try It Online")
This solution works for **large** numbers [Try it online!](https://tio.run/##y00syUjNTSzJTE78n6Zgq/DfN7HCwbGoKLEy2qUovyBaWc3BoVhH2dpaWds8ts6tKD/XJTM9s6S4zkhNxyexuCS62Fa5Lig1MQcmHKtrHqv2P6AoM6/EIS3a0CDO0MDAIPY/AA "Wolfram Language (Mathematica) – Try It Online")
-3 bytes from KellyLowder
[Answer]
# [Python 3](https://docs.python.org/3/), 68 66 60 bytes
 -2 bytes thanks to [Mr. Xcoder!](https://codegolf.stackexchange.com/users/59487/mr-xcoder) 
 -4 bytes thanks to [ovs!](https://codegolf.stackexchange.com/users/64121/ovs) 
 -2 bytes thanks to [Erik the Outgolfer!](https://codegolf.stackexchange.com/users/41024/erik-the-outgolfer) 
```
lambda n:max(n%2**i|n>>i+8<<i for i in range(len(bin(n))-9))
```
[Try it online!](https://tio.run/##FYxBDoIwEADP@ooNiUmL5dBCgSXYj6iHEqluAgshHDTx79UeZyaZ9bO/Fi5juNzi5Ofh4YG72b8Fn0ye05edo3Pb9wRh2YCAGDbPz1FMI4uBWLCUBUoZU@aUr8bWChBRQdOWWoEutW1tIlvV5i8qgxXWjUF7746HdSPeBSvICpcpCOkYfw "Python 3 – Try It Online")
[Answer]
# [Wolfram Language (Mathematica)](https://www.wolfram.com/wolframscript/), 46 bytes
```
Floor@If[#<256,0,Max[#/256,2#0[#/2]+#~Mod~2]]&
```
[Try it online!](https://tio.run/##y00syUjNTSzJTE78n1aaZ/vfLSc/v8jBMy1a2cbI1EzHQMc3sSJaWR/ENlI2ALFitZXrfPNT6oxiY9X@BxRl5pVEA3XqO1SD1FhaWuqYWxgb6hgaG5pamALZpiZmRoY6JkaWJpZm5kaWprWx/wE "Wolfram Language (Mathematica) – Try It Online")
This version can only handle inputs up to 2518-1, otherwise we run into Mathematica's stack size limit. (The bound may vary between Mathematica installations.) The second solution in this answer avoids that.
# How it works
A recursive approach based on the following logic:
* The maximal value should be `0` for any input less than `256`, since taking a byte out of the number eats the whole number. This is our base case, which is why it's included even though the specs promise us we won't have to handle such inputs.
* Otherwise, we take the `Max` of two options: eat the lowest byte (giving us the input divided by `256`) or chop off the lowest bit, recurse on the remaining integer, and append the lowest bit back when we're done.
# [Wolfram Language (Mathematica)](https://www.wolfram.com/wolframscript/), 55 bytes
```
Max@Table[Mod[#,m=2^k]+Floor[#/m/2^8]m,{k,0,Log2@#-8}]&
```
[Try it online!](https://tio.run/##DcxBC4IwFADgHyN06cXac5t7B2GnTgkduo0Jq7RE50AWBOJvX96@0xd8@nTBp@Hpc/@d69z4n7n7x9TZJr5sAaHGdnTHyxTjYgsWGLbaBVhHOMM1vtEUJ725Q74tw5zsXjCzolRARFDpkgMvudRytxQKOQgkQapCkpvLfw "Wolfram Language (Mathematica) – Try It Online")
An alternate version that builds a table instead of recursion, so it works for numbers of any size that Mathematica can handle.
[Answer]
# [Retina](https://github.com/m-ender/retina), ~~71~~ ~~67~~ 64 bytes
```
.+
$*
+`(1+)\1
$+0
01
1
.
$`_$'¶
_.{7}
A`_
O^`
1G`
+1`\B
:$`:
1
```
[Try it online!](https://tio.run/##K0otycxL/K@q4Z7wX0@bS0WLSztBw1BbM8aQS0XbgMvAkMuQS49LJSFeRf3QNq54vWrzWi4ux4R4Lv@4BC5D9wQubcOEGCcuK5UEKy7D//@NTM24LC0tucwtjIE6jQ1NLUwB "Retina – Try It Online") Link only includes the faster test cases, so as not to unduly overload Dennis's server. Edit: Saved 3 bytes thanks to @MartinEnder. Explanation:
```
.+
$*
+`(1+)\1
$+0
01
1
```
Convert from decimal to binary.
```
.
$`_$'¶
_.{7}
A`_
```
Construct a list of strings obtained by deleting 8 consecutive digits in all possible ways.
```
O^`
1G`
```
Sort them in reverse order and take the first (largest).
```
+1`\B
:$`:
1
```
Convert back to decimal. (See @MartinEnder's [explanation](https://codegolf.stackexchange.com/a/102263).)
[Answer]
# [Java (OpenJDK 8)](http://openjdk.java.net/), ~~138~~ 134 bytes
```
i->{int l=0,m=0,x;String y=i.toString(i,2);for(;l<y.length()-7;m=x>m?x:m)x=i.valueOf(y.substring(0,l)+y.substring(l+++8),2);return m;}
```
[Try it online!](https://tio.run/##fY9NSwNBDIbv@ytynGG3Qy1qi9OtoCAIiocepYdpO62p87HMZMoupb99XdsVBaGBQPLmSci7U3s18JV2u/Vni7bygWDXaSIRGvGCkWT2T94ktyL0TjzgU19eoh69i8nqcIn5vZNVaWlwBSujYoRXhe6QRVLUST/Q9NmR3upQQF/MYNmQjlBCi4PZAR2BKYeF7bKWcwrottCUKMifG4bFiMuND0yaaSOMdlv6YHwwlrasZ/a@vrO87vi9Mkm/bVgjYlrG8@qwMDz/K5g8zyf8@2DQlIIDK4@t7F30n@89rsF2Xtj5gfcFKA6HDPqYN5G0FT6RqLo5sZMfoarKNGw8ubm@HV1xLk/88dh@AQ "Java (OpenJDK 8) – Try It Online")
[Answer]
# [ReRegex](https://github.com/TehFlaminTaco/ReRegex), ~~294~~ 275 bytes
*Saved 19 bytes by using better 'function' definitions*
I'd say this is pretty good for a Regex only language.
The base lib does allow for conversion between Unary and Decimal (Which is needed as the challenge spec explicitly states decimal), but does not support Binary; So I had to write that as part of the script adding 120 bytes to it.
```
#import base
b(\d*):(_*)\2_b/b1$1:$2b/b(\d*):(_+)\2b/b0$1:$2b/b(\d+):b/$1/b:b/0/B(_*):1/B$1$1_:/B(_*):0/B$1$1:/B(_*):B/$1/j(\d*),\1(\d)(\d{7})(\d*):/j$1$2,$1$2$3$4:,B:$1$4B/j(\d*),\1\d{0,7}:,?(.*)/,$2,/,((_+)_+),(\2),/,$1,/,(_+),(\1_*),/,$2,/^,(_*),$/d<$1>/j,b:u<(?#input)>b:
```
[Try it online!](https://tio.run/##TU7tCsIwDPzvUwjmRzuDWaYwCWNCn2M4LBviwA/mBoL47DN1DoU0yV3umrR1Wx/rxzAsTufbte3m/nCvZ94UVWTFlJEtktKTZ2CBRJtpsNSBwviPX1rxBExeS0wumIXJgXpL@eJ4xBN0Qd98/sSCtVp9z/RlxzXUqDjBkGANG0En2m/cz6LqGNOX4M6sIkuoakITztNAUyRWMXAgR4J1LY66PYYbEKjKgHNq0Eufmd3idLn1nc29DEO6XfMb "ReRegex – Try It Online")
## By Individual Regexes.
```
#import base
b(\d*):(_*)\2_b/b1$1:$2b/
b(\d*):(_+)\2b/b0$1:$2b/
b(\d+):b/$1/
b:b/0/
B(_*):1/B$1$1_:/
B(_*):0/B$1$1:/
B(_*):B/$1/
j(\d*),\1(\d)(\d{7})(\d*):/j$1$2,$1$2$3$4:,B:$1$4B/
j(\d*),\1\d{0,7}:,?(.*)/,$2,/
,((_+)_+),(\2),/,$1,/
,(_+),(\1_*),/,$2,/
^,(_*),$/d<$1>/
j,b:u<(?#input)>b:
```
## Steps
Firstly, we import the 'base' library, which gives two regexes. One which converts `u<numbers>` into unary. And one which converts `d<unary_underlines>` back into decimal. This is because the challenge requires IO in base10.
Then we define a handful of regexes which convert unary into binary.
```
b(\d*):(_*)\2_b/b1$1:$2b/
b(\d*):(_+)\2b/b0$1:$2b/
b(\d+):b/$1/
b:b/0/
```
The first of these, `b(\d*):(_*)\2_b/b1$1:$2b/` searches for `b`, optionally followed by some binary digits, then a `:`, Then any amount of underlines, followed by the exact same amount of underlines plus one, and finally another `b`.
We then replace that with `b1` followed by the binary digits from before, `:`, and just the first half of the underscores, and finally the last `b`.
So this checks if the unary is not divisible by two, and if so, prepends 1 to it's binary digits, then divides it minus one by two.
The second one, `b(\d*):(_+)\2b/b0$1:$2b/` is almost idendical, however does not check for an extra `_`, meaning it only matches if it is divisible by two, and in this case prepends a `0` instead.
The third one checks if we're out of unary digits, and if so, strips away the padding to just leave the binary digits.
The last one checks if there never was any binary digits supplied, and in that case just leaves `0`.
The next group of Regexes we define are to convert binary back into unary, and are slightly more simple.
```
B(_*):1/B$1$1_:/
B(_*):0/B$1$1:/
B(_*):B/$1/
```
The first of this group, `B(_*):1/B$1$1_:/`, much like its antithesis, detects a `B`, followed by any amount of Unary digits, then `:1`. It doesn't check for the matching `B` in this case, as it is only searching for one digit at a time. If this is matched, it doubles the previously matched amount of unary digits and adds one, then removes the one.
The second, `B(_*):0/B$1$1:/`, is almost idendical to the first, except matches a `0` rather than a `1`, and does not add an additional unary digit.
The last of these, `B(_*):B/$1/`, checks if there are no more binary digits, and if so unwraps the unary. Unlike its antithesis, this does not need a special 0 case.
Next we define the `j` regexes, which act as a splitting function.
```
j(\d*),\1(\d)(\d{7})(\d*):/j$1$2,$1$2$3$4:,B:$1$4B/
j(\d*),\1\d{0,7}:,?(.*)/,$2,/
```
The first, `j(\d*),\1(\d)(\d{7})(\d*):/j$1$2,$1$2$3$4:,B:$1$4B/` does most of the heavy lifting. It searches for `j`, optionally followed by binary digits which are the "incrementer", then a comma followed by the incrementer then exactly 8 binary digits followed by the rest of the binary number, then a `:`. The first of the 8 digits is appended to the incrementer, thus incrementing it, then everything but those 8 digits from the binary input is appended after the `:` following a `,`. So (If we were using 2 digits instead of 8) `j,1001:` would become `j1:1001:,01` then `j10:1001,01,11`. Additionally, the appended array elements are wrapped in `B`s, to convert them back to unary.
The other, `j(\d*),\1\d{0,7}:,?(.*)/,$2,/` checks if there are less than 8 binary digits left to check after the incrementer, and if so, removes everything other than the array wrapped in `,`s. Eg. `,_,___,`
During and after the creation of the array we define the comparison regexes.
```
,((_+)_+),(\2),/,$1,/
,(_+),(\1_*),/,$2,/
```
The first of these, `,((_+)_+),(\2),/,$1,/` checks a comma followed by some amount of underscores, then some more, followed by a comma, then the first amount of underscores, than a comma. It then replaces it with the total amount of underscores in the first element surrounded by `,`s.
The latter, `,(_+),(\1_*),/,$2,/`, checks for a comma followed by some amount of underscores followed by another comma, then the same amount or more underscores, and a last comma. This will instead leave the right element.
Finally, when there is on element left thus matching `^,(_*),$`, we remove the surrounding commas and convert back to decimal via `d<>`. Then no-more regexes can fire and the output is presented.
The input is initially placed into the template `j,b:u<(?#input)>b:`, which first converts the decimal input to unary, eg `5` -> `j,b:_____b:`, then the resulting unary to binary, `j,101:` Then splits the binary (which doesn't work for the example), gets the largest element, converts back to decimal, and done.
[Answer]
# C (gcc), ~~91~~ bytes
```
j;m;t;f(x){for(j=m=0;t=x>>j+8;m<t?m=t:j++)t=t<<j|x%(1<<j);return m;}
```
-23 bytes from [Colera Su](https://codegolf.stackexchange.com/users/75905/colera-su)
Supports up to `2**31-1`
[Try it online!](https://tio.run/##XU7RaoQwEHzWr1gOhERTatRobMz1Q6wUEb0q6JUYi9Tm2228Fnr0ZWdndpmZ5uHSNPs@iFFo0aEVb91VoUGOMhRarufzEHAxFvp5lPppCAKspS6K4Wv1ELWIhWr1oiYYhdn7ScNY9xM6llpdGgLNW63A9y35wLC5znHR7axfm3pu55JVZVSBBNi2iKUEqCFbnucktkhjyjgjjDJLMs6SNKIkplF6PEU0yRIep0lGeMx5GmbGCNex3eGW3lvTUFgoYO4/22uH/lLx46/k32kCgqC/VXTelXXo0KlD3oKtj7eAPObLdCL35fuqDCsC99Y/Gv7/RitsyxnX7N8 "C (gcc) – Try It Online")
Starts with the low 8 bits `(j=0)`, then goes up, changing output if the number with bits `[j,j+8)` cut out is bigger than our current, and continuing until x has no bits above `j+8`
[Answer]
# [Jelly](https://github.com/DennisMitchell/jelly), 12 bytes
```
BJṡ8ḟ@€ƊịBḄṀ
```
[Try it online!](https://tio.run/##ASkA1v9qZWxsef//QkrhuaE44bifQOKCrMaK4buLQuG4hOG5gP///zEzMTU4NQ "Jelly – Try It Online")
Saved bytes thanks to [Jonathan Allan](https://codegolf.stackexchange.com/users/53748/jonathan-allan)!
[Answer]
# JavaScript (ES6), ~~94~~ 91 bytes
*-3 bytes thanks to Justin Mariner*
```
f=(n,d='',c=n.toString(2).match(`(${d}).{8}(.*)`))=>c?Math.max('0b'+c[1]+c[2],f(n,d+'.')):0
```
Just throwing out a JavaScript string-based solution, but I'm hoping someone will post a separate bitwise-based solution so I might learn something.
My solution recursively grabs an 8-bit chunk from the string, taking the maximum value that is found.
```
f=(n,d='',c=n.toString(2).match(`(${d}).{8}(.*)`))=>c?Math.max('0b'+c[1]+c[2],f(n,d+'.')):0
console.log(f(256));
console.log(f(999));
console.log(f(7831));
console.log(f(131585));
console.log(f(7854621));
console.log(f(4294967295));
```
[Answer]
# [C# (.NET Core)](https://www.microsoft.com/net/core/platform), 122+13=135 120+13=133 bytes
```
n=>{int m=0,i=0,t;for(var b=Convert.ToString(n,2);i<b.Length-7;m=t>m?t:m)t=Convert.ToInt32(b.Remove(i++,8),2);return m;}
```
[Try it online!](https://tio.run/##jY7BSsNAEIbP7lPscZemwSSmTdwmooIgVBBb6DlJx7rYnYXdSaCEPHuMguLJepg5DN//zd/4eWMdjK3XeOCbkycwijXHynv@3DNPFemGP7TYrDRSwKdV8m31Drd3JwJe8BGLsp@u3BSXgZ6G1Kt1oqscr4t7ix04Crd2Q256IDCIpdKrOlwDHuhtvlSmoNLc0LWR9At/REpiUYcvYGwHQs9mQSY/sw6odciNGkbFvut1Vu/5U6VRSNazi0nj7RHCndMEa40gfgqLOF1Iqf5m8jw/yyyzJDoLRUmUZuk/XOnVIv7SDWwYPwA "C# (.NET Core) – Try It Online")
+13 for `using System;`
I imagine there is a way of doing this with out using `Convert`. Either way, I'm sure this could be reduced.
### Acknowledgements
-2 bytes thanks to Kevin Cruijssen
### UnGolfed
```
n=>{
    int m=0,
        i=0,
        t;
    // convert n to a binary string,
    // go through removing each possible byte,
    // check if this is the biggest int so far
    for (var b=Convert.ToString(n,2); i<b.Length-7; m=t>m?t:m)
        t=Convert.ToInt32(b.Remove(i++,8),2); // remove 8 bits from position i, then convert from binary string to int
    return m;
}
```
[Answer]
# PHP, 67+1 bytes
```
do$r=max($r,$argn&($x=2**$i++-1)|$z=$argn>>8&~$x);while($z);echo$r;
```
Run as pipe with `-nR` or [try it online](http://sandbox.onlinephpfunctions.com/code/def23552a374ff3641de52e3ed9da2d8c8dc43b5).
[Answer]
# Pyth, 19 bytes
```
eSmi.>>.<.BQd8d2a6l
```
Alternative answer:
```
eSmi.<<8.>.BQdd2a6l
```
Explanation:
```
eSmi.>>.<.BQd8d2a6lQ | Implicit Q at the end, where Q = input
  m             a6lQ | Map the over [0, 1, 2, ... , floor(log base 2 of Q) - 7]
         .BQ         |  Convert Q to binary string
       .<   d        |  Cyclically rotate left by d
      >      8       |  Get string from position 8 to end.
    .>        d      |  Cyclically rotate right by d
   i           2     |  Convert from binary string to integer
eS                   | Find the last element of sorted list (maximum value)
```
The other answer uses a similar approach, except that it rotates right first, and gets all bits except the last 8.
[Answer]
# [MATL](https://github.com/lmendo/MATL), ~~23~~ 21 bytes
```
Bn8-:"GB[]@8:q+(XBvX>
```
[Try it online!](https://tio.run/##y00syfn/3ynPQtdKyd0pOtbBwqpQWyPCqSzC7v9/cwtjQwA "MATL – Try It Online")
```
B                       % Implicitly grab input, convert to binary
 n8-:                   % Create list of 1,2,... n-8, with n the size of the binary string
     "                  % Loop over this list
      GB                % Grab the input again, convert to binary once more.
        @8:q+           % Create indices of a slice of length 8
             [](        % Index into binary string, delete the slice
                XB    % Convert the remainder from binary to integer
                  vX> % Get the maximum number so far.
```
Sadly, `Bn8-:8:!+q&)` only produces the slices to be removed, not the remainder we'd like to keep.
[Answer]
# [Java (OpenJDK 8)](http://openjdk.java.net/), 73 bytes
```
n->{int m=0,i=1;for(;i<n>>7;i*=2)m=Math.max(m,n&~-i|(n>>8&-i));return m;}
```
[Try it online!](https://tio.run/##TY9Pb4JAEMXvfoqJSc1igIgW/62Q2KRNevBkb8bDCquusrtkGayG0q9OkRDtbWZ@b97MO7ELc3TK1Sk@V0Km2iCc6pmbo0jcfa4iFFq5fdppYYYMRfRPszSG3bK7opPmu6RmUcKyDFZMKCg6AO20XbxoEYOsGVmjEeqw2QIzh8xqpABf@lPhR3t2Udf8wE0IO4F8@XZDDgFUygkLoRBkMLBF4NG9NoSKhQrDCRX9YGjJYMXw6Ep2JdJWvV9H/JCaTnuOsCxqOOZGgaRlRZubGRrOJFH8G2rbzbYY@mMbZrOZDZPpyLPBG3n@1L93/ut46JVWswbg7vSVx@TRppyfiQAnhGJ9y5BLV@fopnVM3JPuizeI59C1QVj0aSFZ2mQmj4gPVOd6Z9GRPL3m88YsUdb987JTVn8 "Java (OpenJDK 8) – Try It Online")
[Answer]
# [Octave](https://www.gnu.org/software/octave/), ~~81~~ 80 bytes
```
@(x)max(bin2dec(dec2bin(x*(c=2.^(0:(b=nextpow2(x+1)-8))))(:,[1:b b+9:end]))'./c)
```
[Try it online!](https://tio.run/##TclRC4IwFAXg936Fb96bbbWrU@9A6H9EgZsTfEiFpPbvl1FgBw6cjzO5pX362DdSyniGgPc2gB1G6ryDtbRuCHtwDckbnAzYZvRhmacXQcgUihrXgDlclLGJzdj4sbsipvLoMHbDY4ZUCJHirgfSZfLNR8z8p6rO1SaVK13r7dNFSeqngrjgsiLWGN8 "Octave – Try It Online")
This is a different solution to my original attempt, saving a further 14 bytes.
The code is broken down as follows:
```
@(x)max(                                                                       )
        bin2dec(                                                          )'./c
                                                         (:,[1:b b+9:end])
                dec2bin(x*(                            ))
                           c=2.^(0:                   )
                                   (b=nextpow2(x+1)-8)
```
On the sixth line the number of groups is calculated by finding the exponent of the next power of two larger than the input (number of bits in input number), and subtracting 7 as we are removing 8 bits from each group - the resulting number is stored in `b` for later.
We then calculate an array of powers of two on the fifth line which is large enough for all the possible groups that can be removed. We save this in variable `c` for later.
On the next line up (forth line), we multiply the input by the array of powers of two (essentially bit shifting each number up), and convert the result to binary. If we take the example of 7831, this results in a 2D array containing:
```
000001111010010111
000011110100101110
000111101001011100
001111010010111000
011110100101110000
111101001011100000
```
If we then chop out the centre 8 bits, that is equivalent to removing each of the groups of 8 bits. This is done by the third line.
The resulting array is converted back to decimal on the second line. We also have to divide by `c` to undo the scaling that was done to each group initially.
Finally on the first line an anonymous function is declared, and the maximum value from all groups is calculated.
---
* Save 1 byte by using `nextpow2(x+1)` rather than `nnz(bin2dec(x))`
---
---
### Original attempt - ~~120 98~~ 95 bytes
```
@(x)max(bin2dec(reshape(repmat(a=(d=@dec2bin)(x)',1,b=nnz(a)-7)(d(255*2.^(0:b-1))'<49),[],b)'))
```
[Try it online!](https://tio.run/##TYrRCsIgGEbve4ru/P9QSafbjIS9RxRoOtrF1mgjRi9vRsH6bj4O59yvs3vG1FrOeWpgwd4t4LtBhniFR5xuboz5x97N4CwE22Qhc4C5JVRQb4fhBQ5ZhRBAar2T/AL7g2cCkRyVQXo6U48EMYVuGoEwxghu2tyW2@8@ZIz5o6ouxEqiELrWq9OqlOJHShplykoajekN "Octave – Try It Online")
The code is split up as follows:
```
@(x)max(                                                                                      )
        bin2dec(                                                                             )
                reshape(                                                              ,[],b)'
                        repmat(a=(d=@dec2bin)(x)',1,b=nnz(a)-7)(                     )
                                                                d(255*2.^(0:b-1))'<49
```
Basically it calculates a matrix containing the possible groups of values that can be removed, and then works out which ends up giving the largest number.
Working line by line, the fifth line calculates the groups that can be removed. For example, take 7831. This is a 13bit number, giving the groups:
```
1111100000000
1111000000001
1110000000011
1100000000111
1000000001111
0000000011111
```
The result of the fifth line is a 2D logical array which can be used for indexing.
The fourth line of the code converts the input to an array of the bits (represented as characters '0' and '1'), and then replicates it `n`-7 times (where `n` in number of bits) giving one line for each possible grouping. The group mask above is used to remove each of the possible groups.
On the third line, the result is then reshaped to undo the unwanted flattening that resulted from applying the group mask. The second line converts back to an array of resulting decimal numbers. And the first line defines the anonymous function to be the maximum value of array of possible groups.
---
[Answer]
# [Perl 5](https://www.perl.org/), 78 + 1 (`-p`) = 79 bytes
```
map{$\=$"if($"=oct$s=~s/.{$_}\K.{8}//r)>$\}2..length($s=sprintf'0b%b',$_)-10}{
```
[Try it online!](https://tio.run/##K0gtyjH9/z83saBaJcZWRSkzTUNFyTY/uUSl2LauWF@vWiW@NsZbr9qiVl@/SNNOJabWSE8vJzUvvSRDA6ikuKAoM68kTd0gSTVJXUclXlPX0KC2@v9/cwtjw3/5BSWZ@XnF/3ULAA "Perl 5 – Try It Online")
[Answer]
# [Ruby](https://www.ruby-lang.org/), 55 bytes
```
->n{(8../$/=~"%b"%n).map{|r|n>>8&(a=-1<<r-8)|n&~a}.max}
```
[Try it online!](https://tio.run/##JYzBCoQgFAB/RWKLAjW0NB@kPyIe7NBtJYTAJe3X3ZY9zgxMPLdP3XUlJly9onR8jfpu2q1pw0Df/rhyzMEY1fVeE7aukaghh@725ampVMuFxAgAMFrUxDBiExNK/EjMkj9i5jCDXDgI9x@mjA5kE95tcq7ULw "Ruby – Try It Online")
[Answer]
# Perl, 53 bytes
(the `use 5.10.1` to bring perl to lanugage level 5.10.1 is free)
Give the input number on STDIN.
Will run out of memory for big numbers, but the 32-bit number in the input is not yet a problem
```
#!/usr/bin/perl
use 5.10.1;
$_=sprintf"%b",<>;/.{8}(?{\$F[oct"0b$`$'"]})^/;say$#F
```
]