I have a binary file with vertex normals. The value is coded as byte. How do I encode angle from byte and convert the angle to float? Example:
binary: 128, 128, 255
obviously in angles it's: 90*, 90*, 180*
How do I get a value in float?
Values are obviously 0.5 0.5 1.0 but what's the c# code so I can convert byte from 128 to 0.5f?
byte
has a range of [0..255]
, so if you're mapping it to a [0.0..1.0]
range, it's simple math:
double angle = byteValue / 255.0;
At that point, you can then multiply by whatever angle system you desire.
// Degrees
double angleDeg = angle * 360.0;
// Radians
double angleRad = angle * 2.0 * Math.PI;