Conversão de tipo de dados

22/09/2004

0

Pessoal

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

Edison_br

Responder

Posts

22/09/2004

Edison_br

Pessoal

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.


Responder

23/09/2004

Edison_br

Pessoal a forma de gravação do float no PDB é IEEE 754 floating-point ´single format´ bit layout.

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


Responder

23/09/2004

Ipc$

Creio que assim seria mais simples:
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;



Responder

Assista grátis a nossa aula inaugural

Assitir aula

Saiba por que programar é uma questão de
sobrevivência e como aprender sem riscos

Assistir agora

Utilizamos cookies para fornecer uma melhor experiência para nossos usuários, consulte nossa política de privacidade.

Aceitar