I have a mac adress stored with type mac address in postgresql. I need to convert the first octet in the information about I/G bit and U/L bit (more infos).
Example: mac address is AA-BB-CC-DD-EE-FF. The first Octet is then AA. Converted to Binary: 0101 01010. The last bit represents I/G: 0. The second from right to left is the U/L bit: 1.
How can I do this in a postgresql query?
This is what I have so far:
select id, mac, left(mac::text,2) as octet
from mytable
The return is:
id,mac,octet
13,aa:XX:XX:XX:XX:XX,aa
I also tried left(mac::text,2)::integer as integer, but I get the error message [22P02] ERROR: invalid input syntax for integer: "aa"
The result I want is the following:
id, mac, octet, binary, ig_bit, ul_bit
13, aa:XX:XX:XX:XX:XX,aa, 1010 1010, 0, 1
So I have isolated the first bit, however, the format is 'text' and I can't convert it to integer or binary.