Skip to main content
11 of 11
added 76 characters in body
0x45
  • 798
  • 4
  • 17

Java, ... 194 191 186 Bytes

static int f(int n){char[] c=Integer.toBinaryString(n).toCharArray();int j=0,o=2^32-2,i=c.length,l=i-1;if(n<0|n>o)return 0;for(;j<2&i>0;j+=c[--i]==48?1:0);if(j==2)return l-i;return 0;} 

-159 Bytes for using smaller variable names and removing whitespace
-25 Bytes, after taking even shorter variables and thanks to @KevinCruijssen tips
-18 Bytes, more whitespaces, function name
-3 Bytes, thanks to @KevinCruijssen, shortening if condition
-5 Bytes, Thanks to @Arnold Palmer, @KevinCruijssen, shortening loop

Ungolfed

public static int getPosSecondZero2(int number){ int overflow = 2^32-2; if(number < 0 || number > overflow){ return 0; } String binaryString = Integer.toBinaryString(number); char[] binaryCharArray = binaryString.toCharArray(); int count = 0; int idx = binaryCharArray.length; int length = binaryCharArray.length -1; while(count < 2 && idx>0){ idx--; if(binaryCharArray[idx] == '0'){ count++; } } if(count == 2) return length-idx; return 0; } 
0x45
  • 798
  • 4
  • 17