1. Home
  2. Computing & Technology
  3. Delphi Programming
Glossary|Tips/Tricks|FREE App/VCL|Best'O'Net|Books|Link Back

Delphi Programming RTL Reference|By Category|Alphabetically|By Unit
 

BinToHex

unit
Classes
category
type conversion routines

declaration
procedure BinToHex(BinValue, HexValue: PChar; BinBufSize: Integer);

description
Converts a binary value to its hexadecimal representation.

HexValue returns a null-terminated string that represents the (binary) value of BinValue as a hexadecimal number. BinBufSize is the size of BinValue. HexValue needs to point to a sequence of characters that has at least 2*BinBufSize bytes because each hexadecimal character represents two bytes.

example
// drop 3 TLabel components on a Form
// and assign the code to form create

var
  E: Extended;
  //Make sure there is room for null terminator
  Buf: array[0..SizeOf(Extended) * 2] of Char;
begin
  E := Pi;
  Label1.Caption := Format('Pi starts off as %.15f', [E]);
  BinToHex(@E, Buf, SizeOf(E));
  //Slot in the null terminator for the PChar, so we can display it easily
  Buf[SizeOf(Buf) - 1] := #0;
  Label2.Caption := Format('As text, the binary contents of Pi look like %s', [Buf]);
  //Translate just the characters, not the null terminator
  HexToBin(Buf, @E, SizeOf(Buf) - 1);
  Label3.Caption := Format('Back from text to binary, Pi is now %.15f', [E]);
end;

in real code
Base Conversions, and more
Routines for converting Int to Bin, Int to Hex, Int to Roman and vice versa.

see also
HexToBin,


 Free Delphi code snippet inside every Delphi Newsletter!
Subscribe to the Newsletter
Name
Email

 Got some code to share? Got a question? Need some help?
Explore Delphi Programming
About.com Special Features

Stay connected and entertained with reviews on tips on the latest HDTVs, cellphones and more. More >

Easy ways to connect two computers for networking purposes. More >

  1. Home
  2. Computing & Technology
  3. Delphi Programming

©2009 About.com, a part of The New York Times Company.

All rights reserved.