Conversão de tipo de dados
22/09/2004
0
Estou implementando um Conduit(para HotSync) em delphi e preciso escrever um integer em sua forma de 4 byte, como posso implementar isto.
Preciso também para float;
Grato pela atenção
Edison
Edison_br
Posts
22/09/2004
Edison_br
Consegui uma rotina em java,
Portei ela... e funcionou...
ficou assim:
unit UConverter;
interface
type
//Definição de Tipos
TByteArray = array of Byte;
TConverter = class
Public
Function IntTo4Byte(Inteiro:Integer):TByteArray;
end;
var
Converter: TConverter; //Classe Instanciada
implementation
{ TConverter }
function TConverter.IntTo4Byte(Inteiro: Integer): TByteArray;
Var
Ret : TByteArray;
i : Integer;
begin
SetLength(Ret,4);
i := Inteiro;
Ret[3] := byte(i and 255);
i := i shr 8;
Ret[2] := byte(i and 255);
i := i shr 8;
Ret[1] := byte(i and 255);
i := i shr 8;
Ret[0] := byte(i and 255);
Result := Ret;
end;
end.
23/09/2004
Edison_br
floatToIntBits
public static int floatToIntBits(float value)
Returns a representation of the specified floating-point value according to the IEEE 754 floating-point ´single format´ bit layout.
Bit 31 (the bit that is selected by the mask 0x80000000) represents the sign of the floating-point number. Bits 30-23 (the bits that are selected by the mask 0x7f800000) represent the exponent. Bits 22-0 (the bits that are selected by the mask 0x007fffff) represent the significand (sometimes called the mantissa) of the floating-point number.
If the argument is positive infinity, the result is 0x7f800000.
If the argument is negative infinity, the result is 0xff800000.
If the argument is NaN, the result is 0x7fc00000.
In all cases, the result is an integer that
se Alguém puder ajudar!!!
[]Edison
23/09/2004
Ipc$
type TIArray = array[0..3] of Byte; type TFArray = array[0..7] of Byte; function Convert_Int(i:Integer):TIArray; begin Move(i, Result[0], 4); end; function Convert_Float(f:Double):TFArray; begin Move(f, Result[0], 8); end;
Clique aqui para fazer login e interagir na Comunidade :)