For your example, sure there is:
Precalculate the SHA hash of every number less than $2^{40}$. Store those hashes in a database.
To check if a hash belong to a number less than $2^{40}$, look it up in the database. If you find it, the answer is yes, otherwise no.
Sure, that'll take a bunch of precalculation and a rather large database, but it's quite possible to do with modern hardware.
You could optimize the database size a little, e.g. down to 80 bits per entry by only storing the first 40 bits of the hash and the 40-bit number that produced it, letting you verify the match by hashing the number. Or you could even store just, say, the first 32 bits of each hash and a list of the all the (256 or so) numbers that produced it, getting down to only slightly over 40 bits per entry at the cost of 256 hash computations per lookup on average. If you don't mind some occasional false positives, even more impressive space savings are possible e.g. using a Bloom filter.
In the general case, though, assuming that:
- the groups you wish to distinguish are large enough that precalculating the hashes of all (or even most) elements of either of them is not practical, and
- the definitions of the groups don't have anything to do with the hash function used (i.e. you may not choose "strings whose hash begins with a zero" as one of the groups),
then it is generally not feasible to determine which group a string belongs to just from its hash.
Note that resistance to this kind of "generalized preimage attack" does not follow from the standard preimage and collision resistance properties that a secure cryptographic hash is expected to satisfy. Still, if anyone were to find an efficient distinguisher like that for a widely used hash, that would certainly be considered by most cryptographers a notable attack on the hash function.