I have my Longitude in Hex FF676980(4 bytes), I want to convert it into degrees in c#, how can I do it?
Asked
Active
Viewed 970 times
-2
-
1Hi and welcome to Stack Overflow. Please update the question with the code you already tried. – Cosmin Staicu Sep 13 '19 at 05:29
-
Latitude and longitude are numbers with many decimal positions that can be either positive or negative. I wonder how that data was encoded into 4 bytes. How do you know the sign? What about the decimal point location? Your question imho lacks information so others can help you. – Cleptus Sep 13 '19 at 06:39
1 Answers
1
Normally geotags are 24bytes but for photos where a precise location is not desired a 4 byte geotag is often used. So its only natural to assume that this is your use case, you should#ve just read the wikipedia article (https://en.wikipedia.org/wiki/Geotagging#Photographs) and got over with it instead of asking.
Anyways heres your code:
public static (int D, int M, decimal S) Parse4ByteHexGeoTag(string hex)
{
var deg = Convert.ToInt(hex.SubString(0,2));
var time = Convert.ToDecimal(hex.SubString(3))/60m;
var min = (int)time;
var sec = (time%60)*60;
return (deg, min, sec);
}
Note that you should have an enum indicating if its N or S, W or S, depending on wether deg
is positive or not.

Prophet Lamb
- 530
- 3
- 17