I have been fooling arround with Net::LDAP to query an exchange system. I want to get the NT account name
from the query, but I get a value that looks like this:

010500000000000515000000C60B7E00B719917EF21E5310FA0E0000

after reading some stuff over at M$oft, it seems that Exchange stores the NT SID in hex format
as opposed to binary (as the OS does). I found this code snippet for VB to convert it to binary:
'The SID is stored in a hexadecimal representation of the binary SID 'so we convert it and store it in a byte array tmp = Len(strSID) / 2 - 1 ReDim bByte(tmp) As Byte For i = 0 To tmp - 1 bByte(i) = CInt("&h" & Mid(strSID, (i * 2) + 1, 2)) Next 'Allocate space for the strings so the API won't GPF strName = Space(64) strDomain = Space(64) 'Get the NT Domain and UserName 'Note: This can't be done from VBScript directly 'because VBScript doesn't support making the 'LookupAccountSid API call ret = LookupAccountSid(vbNullString, bByte(0), strName, Len(strName) +, strDomain, Len(strDomain), iType

can anyone help me with the first part here where the hex value is stored in a byteArray ?
i assume we need pack here but, sadly, i am one of the many who do not understand pack.

humbly,
novitiate

"...goodnight you princes of main(e)"  --The Cider House Rules

In reply to pack hex to bin by novitiate

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.