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

Java, 408 401 396 237 212 Bytes

static int getPosSecondZero(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;while(j<2&&i>0){i--;if(c[i]=='0'){j++;}}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

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