If you know the uncompressed?
Look at the value of the y-coordinate. If the last digit is an odd number (1, 3, 5, 7, 9) then use a prefix of "03". If it is not an odd number (0, 2, 4, 6, 8 ) then use a prefix of "02"
Here's an example:
Uncompressed public key (prefix in black, x-value in blue, y-value in red):
04890821F2C9C8A01DDD5C019E75FD6D46D41D4575047CDEDD7946AA56EAE01A80FCA0ABC7E90526EB41EA6A9E4C6FA0A9FCED8DCF7E25FCD46509FFF2BD5088B8
Notice that the final digit of the red portion (y-value) is 8. So, we throw away that red portion, and change the prefix from 04 (uncompressed) to 02 (compressed/even):
02890821F2C9C8A01DDD5C019E75FD6D46D41D4575047CDEDD7946AA56EAE01A80
Here's another example:
Uncompressed public key (prefix in black, x-value in blue, y-value in red):
041C2E319C3F82FE654A77B6DF323166E1D771974B64CEF70F5AB97EAC9DA1A7CCDC44D9E9E893B53C9968C3D41EF20356484243530027456BFCF1AD97AC223839
Notice that the final digit of the red portion (y-value) is 9. So, we throw away that red portion, and change the prefix from 04 (uncompressed) to 03 (compressed/odd):
031C2E319C3F82FE654A77B6DF323166E1D771974B64CEF70F5AB97EAC9DA1A7CC
An uncompressed point has an x-coordinate and a y-coordinate. To get the compressed value, just throw away the y-coordinate, and add the appropriate (02 or 03) prefix.
Correct. That's what you asked for, twice.
See here: