Skip to content
Snippets Groups Projects
Commit 02161021 authored by Matthias Bernien's avatar Matthias Bernien
Browse files

add Str2Float32 function

parent 87fcbb55
Branches
No related tags found
No related merge requests found
...@@ -138,3 +138,24 @@ function rmByIndex(Arr, Idx) { ...@@ -138,3 +138,24 @@ function rmByIndex(Arr, Idx) {
return narr; return narr;
} }
exports.rmByIndex = rmByIndex; exports.rmByIndex = rmByIndex;
/**
* Konvertiert einen String von 4 Zeichen (= 4 Byte)
* in ein Float32 gemäß IEEE 754. Dabei wird der
* String als binäre Codierung interpretiert.
*
* @author Matthias Bernien
* @param Arr Array Datenreihe
* @param Idx Integer "skip" Index
* @return res Array resultierendes Array
*/
function Str2Float32(Str) {
var buffer = new ArrayBuffer(4);
var bytes = new Uint8Array(buffer);
for (let i = 0; i < 4; i++) {
bytes[i] = Str.charCodeAt(i);
}
var view = new DataView(buffer);
return view.getFloat32(0, false);
}
exports.Str2Float32 = Str2Float32;
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment