E
eywitteveen
Hello,
Introduction:
I'm currently working on retrieving altitude values from a a
file(srtm). This file contains a array of byte values and depending of
the position i want to know, i have to read to byte's to know what the
altitude is. This works fine, till i want to convert the bytes to a
integer value, representing the height on that specific place on the
world.
The problem:
I have 2 bytes, which represents a signed integer (this means the
value can als be negative), so i want a function with the following
definition.
public static int getSignedIntegerBigEndianFromWord(byte[] word) {
...............
}
I looked at the BitConverter.GetBytes(), but this only works for
unsigned integers AFAIK.
Am i overlooking something?
Validation data:
byte[0] byte[1] 0-in bits 1-in bits word in bits expected value
255 236 11111111 11101100 1111111111101100 -20
255 246 11111111 11110110 1111111111110110 -10
255 255 11111111 11111111 1111111111111111 -1
0 0 00000000 00000000 0000000000000000 0
0 1 00000000 00000001 0000000000000001 1
0 10 00000000 00001010 0000000000001010 10
0 20 00000000 00010100 0000000000010100 20
ps: i just feel like i'm at school again, trying to solve such an easy
task
Eduard Witteveen
Introduction:
I'm currently working on retrieving altitude values from a a
file(srtm). This file contains a array of byte values and depending of
the position i want to know, i have to read to byte's to know what the
altitude is. This works fine, till i want to convert the bytes to a
integer value, representing the height on that specific place on the
world.
The problem:
I have 2 bytes, which represents a signed integer (this means the
value can als be negative), so i want a function with the following
definition.
public static int getSignedIntegerBigEndianFromWord(byte[] word) {
...............
}
I looked at the BitConverter.GetBytes(), but this only works for
unsigned integers AFAIK.
Am i overlooking something?
Validation data:
byte[0] byte[1] 0-in bits 1-in bits word in bits expected value
255 236 11111111 11101100 1111111111101100 -20
255 246 11111111 11110110 1111111111110110 -10
255 255 11111111 11111111 1111111111111111 -1
0 0 00000000 00000000 0000000000000000 0
0 1 00000000 00000001 0000000000000001 1
0 10 00000000 00001010 0000000000001010 10
0 20 00000000 00010100 0000000000010100 20
ps: i just feel like i'm at school again, trying to solve such an easy
task
Eduard Witteveen