$float32

From Scriptwiki
Revision as of 00:16, 2 October 2008 by Aca20031 (talk | contribs)

(diff) ← Older revision | Latest revision (diff) | Newer revision → (diff)
Jump to: navigation, search

Converts four bytes to a 32-bit float

$float32(byte1, byte2, byte3, byte4)

All credits go to Saturn

Script

alias float32 {
  var %d = $calc($1 + $2 * 256 + $3 * 256^2 + $4 * 256^3)
  var %e = $calc($and(%d,$calc(2^31-2^23))/(2^23))
  var %m = $base(1. $+ $right($base(%d,10,2,23),23),2,10)
  return $calc(-1^$isbit(%d,32) * %m * 2^(%e - 127))
}