Actionscript 3에서 Binary C float를 읽으시겠습니까?
-
12-09-2019 - |
문제
Binary C/C ++ 데이터 유형 (예 : C Float의 메모리 버전)이있어 Actionscript 3을 읽어야하며 처음부터 코딩하지 않기를 원합니다.
라이브러리, 샘플 코드, 의사 코드를 도와주는 사람이 있습니까?
예를 들어:
C/C ++ 앱 :
float f = 1.1;
SaveFloatToFile(f, 'myfile.bin');
ActionScript 3 앱 :
var ba:ByteArray = ReadFromFile('myfile.bin');
var f:Float = ParseFloat(ba); // I need code for ParseFloat()
해결책 2
나는 좀 더 파고 들었고 Bytearray가 내가 필요한 대부분의 것을 가지고 있음을 발견했습니다 (아마도 약간의 약간의 변화가있을 수 있음)
다른 팁
AS3 숫자 클래스는 다음과 같습니다 IEEE 754, JavaScript 번호 클래스와 동일합니다.
AS3 라이브러리를 검색하는 대신 AS3에서 약간의 수정만으로 작동 해야하는 JavaScript 코드를 파헤 쳤습니다.
에 이 지역 나는이 고밀도 플로트 파서를 발견했다.
p.decodeFloat = function( data, precisionBits, exponentBits ){
var b = new this.Buffer( this.bigEndian, data );
b.checkBuffer( precisionBits + exponentBits + 1 );
var bias = Math.pow( 2, exponentBits - 1 ) - 1, signal = b.readBits( precisionBits + exponentBits, 1 ), exponent = b.readBits( precisionBits, exponentBits ), significand = 0,
divisor = 2, curByte = b.buffer.length + ( -precisionBits >> 3 ) - 1;
do
for( var byteValue = b.buffer[ ++curByte ], startBit = precisionBits % 8 || 8, mask = 1 << startBit; mask >>= 1; ( byteValue & mask ) && ( significand += 1 / divisor ), divisor *= 2 );
while( precisionBits -= startBit );
return exponent == ( bias << 1 ) + 1 ? significand ? NaN : signal ? -Infinity : +Infinity : ( 1 + signal * -2 ) * ( exponent || significand ? !exponent ? Math.pow( 2, -bias + 1 ) * significand : Math.pow( 2, exponent - bias ) * ( 1 + significand ) : 0 );
};
코드를 디버기하고 기능적으로 선호하는 경우 이 코드 대신에 더 도움이됩니다.
제휴하지 않습니다 StackOverflow