--- oup/rewrite/Global/Functions.pas 2007/01/22 23:05:45 97 +++ oup/current/Global/Functions.pas 2007/02/21 03:12:33 109 @@ -10,6 +10,7 @@ function Decode_Int(buffer: TByteData): function Encode_Int(input: LongWord): TByteData; function Decode_Float(buffer: TByteData): Single; function Encode_Float(input: Single): TByteData; +function IntToBin(Value: Byte): String; function DataToBin(Data: TByteData): String; function BinToInt(bin: String): Byte; @@ -38,7 +39,6 @@ type - function BoolToStr(bool: Boolean): String; begin if bool then @@ -48,8 +48,6 @@ begin end; - - function HexToLong(hex: String): LongWord; function NormalizeHexString(var hex: String): Boolean; @@ -75,43 +73,18 @@ function HexToLong(hex: String): LongWor begin if NormalizeHexString(hex) then - begin - Result := StrToInt(hex); -{ - hex := UpperCase(hex); - Result := 0; - for i := 1 to Length(hex) do - begin - Result := Result shl 4; - case hex[i] of - '0'..'9': - Result := Result + Ord(hex[i]) - 48; - 'A'..'F': - Result := Result + Ord(hex[i]) - 55; - else - Result := 0; - Exit; - end; - end; -} - end + Result := StrToInt(hex) else - begin Result := 0; - end; end; - - function Decode_Int(buffer: TByteData): LongWord; begin Result := buffer[0] + buffer[1] * 256 + buffer[2] * 256 * 256 + buffer[3] * 256 * 256 * 256; end; - - function Encode_Int(input: LongWord): TByteData; begin SetLength(Result, 4); @@ -125,8 +98,6 @@ begin end; - - function Decode_Float(buffer: TByteData): Single; var _valueswitcher: TValueSwitcher; @@ -138,8 +109,6 @@ begin end; - - function Encode_Float(input: Single): TByteData; var _valueswitcher: TValueSwitcher; @@ -149,6 +118,14 @@ begin end; +function IntToBin(Value: Byte): String; +var + i: Byte; +begin + Result := ''; + for i := 7 downto 0 do + Result := Result + IntToStr((Value shr i) and $01); +end; function DataToBin(Data: TByteData): String; @@ -172,8 +149,6 @@ begin end; - - function BinToInt(bin: String): Byte; var Add: Integer; @@ -195,7 +170,6 @@ end; - function FormatNumber(Value: LongWord; Width: Byte; leadingzeros: Char): String; begin Result := AnsiReplaceStr(Format('%' + IntToStr(Width) + 'u', [Value]), ' ', leadingzeros);