Re: bytes To Hex

Tech-Archive recommends: Speed Up your PC by fixing your registry





My Byte[] array consists of DirectoryServices Users Sid from the domain

I needed to Convert Each Byte to a Hex String , Then Concatenate each
following byte

below is a example...is the proper way, or is there a better way of
accomplishing this

uint uDec;

for (int x = 0; x < aBytes.GetLength(0); x++)
{

uDec = Convert.ToUInt32(aBytes[x]);

sHexId.Append(String.Format("{0:x2}",uDec));

}
Console.WriteLine(sHexId);

//it matches the hex id Sql Returns



Tks



"Peter Duniho" <NpOeStPeAdM@xxxxxxxxxxxxxxxx> wrote in message
news:op.t52de5bw8jd0ej@xxxxxxxxxxxxxxxxxxxxxxx
On Tue, 05 Feb 2008 10:04:28 -0800, Analizer1 <dvs_bis@xxxxxxxxxxxxx>
wrote:

Hi I have a Long Number
In a Byte[]

Im not sure how to convert this Byte[] array to a Hex
string

Well, the .NET way would be to use BitConverter to get the bytes into an
actual long value, and then use ToString("x") to convert to hex:

byte[] rgb = { 1, 2, 3, 4, 5, 6, 7, 8 };
string strHex = BitConverter.ToInt64(rgb, 0).ToString("x");

Pete


.



Relevant Pages

  • Re: SQLCI - Insert/Select in Hex
    ... want a hex representation of the AMT number? ... '0x' prefix from the hex string then you can use SUBSTRING with TRIM: ... UPDATE STATISTICS FOR TABLE =HEXVALS; ... EXECUTE INS USING 0,'00'; ...
    (comp.sys.tandem)
  • Re: What is error 8007f003
    ... Here's my procedure for getting both decimal values for any 4-byte hex ... View and assumes you have the hex string in the Clipboard to start with. ... press F5 (change the initial mode to Hex and Qword) ... press F5 (convert to decimal in Dword mode, ...
    (microsoft.public.windowsupdate)
  • Re: Retrieving int from hex in a file.
    ... a in now a string full of hex representations in the form: ... It doesn't contain a "hex ... That converts a hex string into an integer, ... You have a string containing binary data. ...
    (comp.lang.python)
  • Re: Converting binary sids to a hex string
    ... binary sid to a hex string. ... print MySid ...
    (comp.lang.python)
  • Re: color tool
    ... Thomas Weidenfeller wrote: ... >> JSliders with the hex value computing. ... It is very easy to convert an int to a hex string. ... String Integer.toString(int i, int radix); ...
    (comp.lang.java.gui)