ATTEMPT 1:
Store 2 binary trees, one for the start values โโand one for the end values. Your nodes for both trees (or simply "end") have a property that refers to unique ranges with some id (the initial value of the range).
Do a binary search in the "start" tree to narrow the list down to ranges where the start is less than or equal to your search value. Do the same in the "end" tree, where the value is greater than or equal to the search value. Find the intersection of the nodes of both trees, and these ranges contain your search value.
You can find the intersection using a hash map / set for optimal performance.
ATTEMPT 2:
What if you saved a hash list for intervals when keys are the first but a large number of bits that are separated by both start and end values?
So, if start is "11001101" and end is "11010010", the key is "110". Each key will display a list of ranges (beginning and end) that share the key.
When searching for a value, to see what ranges they are in, for example, "00101111", you will have to look for a hash list for n different values โโor where n is the number of bits (32 in your case). In this case, you will search for "00101111", "0010111", "001011", etc. For each hit, you will need to check that the search value is in the range.
At first glance, it seems to me that on average for each hit you get half the false positives, but it doesnโt matter if the number of hits is small, and the more keys, the fewer hits it should receive.
There is a small problem, say, the beginning of โ00101110โ and the end of โ01100111โ, because the key will be โ0โ, which means a significant amount of โfalse positivesโ. It would be better if there were two different keys: "001" and "01", although I'm not sure about the specific algorithm that you need for coding for this optimization. If the ranges are small enough, and this problem can be solved or skipped, then you can get a very fast search, since most of the keys will be relatively long and will not match the search queries.