greubel
Visitor
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
07-20-2014
01:25 PM
roByteArray to float or double
Has anyone come up with a way to convert a 4 byte or 8 byte binary value in a roByteArray to a real floating point number ?
And visa versa, float or double to a 4 or 8 byte binary value.
And visa versa, float or double to a 4 or 8 byte binary value.
5 REPLIES 5

RokuMarkn
Visitor
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
07-20-2014
01:30 PM
Re: roByteArray to float or double
The 4 or 8 byte value in the ByteArray -- is this formatted as an IEEE floating point number? Or is it an integer?
--Mark
--Mark
greubel
Visitor
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
07-20-2014
02:27 PM
Re: roByteArray to float or double
IEEE float as eight bytes, 3F F0 00 00 00 00 00 00 = 1.0
EnTerr
Roku Guru
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
07-21-2014
12:45 PM
Re: roByteArray to float or double
In a perfect world, roByteArray should get couple of pack/unpack methods:
I keep getting those urges to sketch a BSc function unpacking 4-byte float but not having a way to inject NaN, minus 0 and +/-Infinity values (luckily) keeps me from doing it.
function ifByteArray.unpack(fmt as String) as roArraywhere fmt = sequence of format characters:
function ifByteArray.pack(fmt as String, data as roArray) as Boolean
fmt BrSc type Size, octets
- --------- ------------
c String 1
b Integer 1
h Integer 2
i Integer 4
f Float 4 in IEEE 754
d Double 4 in IEEE 754
s String zero-terminated utf-8
? Boolean 1
I keep getting those urges to sketch a BSc function unpacking 4-byte float but not having a way to inject NaN, minus 0 and +/-Infinity values (luckily) keeps me from doing it.
greubel
Visitor
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
07-21-2014
12:53 PM
Re: roByteArray to float or double
I was hoping you would have a method !
EnTerr
Roku Guru
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
07-21-2014
02:30 PM
Re: roByteArray to float or double
Oh, "the things I'm gonna do for my country"*:
(*) And curiousity, and vanity.
inf = 1e39
NaN = 0 * inf
negZero = -1 / inf
BrightScript Debugger> ? inf, NaN, negZero
inf nan -0
BrightScript Debugger> ? (negZero = 0), 0 * NaN, inf * NaN
true nan nan
(*) And curiousity, and vanity.