Using bit operators

from the Artful Common Queries page


If you store ipaddress values in a 32-bit unsigned int column, you can retrieve octets with bit-shifting:
select 
  ipAddress, 
  (ipAddress >> 24) as firstOctet,
  (ipAddress>>16) & 255 as secondOctet,
  (ipAddress>>8) & 255 as thirdOctet,
  ipAddress & 255 as fourthOctet
from ...

Last updated 17 Feb 2025