But why do we need the bitwise AND for that, specifically? I understand the idea, but would it not be easier to only parse the IP address string of bits only for the first n bits and then disregard the remainder (the host identifier)?
Essentially it boils down to:
bit operations are stupid fast and efficient, String operations are super slow.
Also, IP addresses are always stored as int32/int64, so applying String operations would require them to be converted first.