#1
  1. No Profile Picture
    Junior Member
    Devshed Newbie (0 - 499 posts)

    Join Date
    Jul 2000
    Posts
    3
    Rep Power
    0
    I have a situation where I have an
    8-byte string which is represented as
    16 hex digits. How do I convert a 16 hex
    digit string to an 8-byte binary string?
    I know I can use bin2hex to go from
    a binary string to a hex string (very useful)
    but is there a way to go the other direction?
    Right now I have a solution, which is
    to use a loop to go through the hex string
    one byte at a time, but that doesn't seem
    like a good way to do it. It seems
    like I should be able to use the pack()
    command, but I can't get it to work.

    Thanks
  2. #2
  3. No Profile Picture
    Junior Member
    Devshed Newbie (0 - 499 posts)

    Join Date
    Jul 2000
    Posts
    3
    Rep Power
    0
    Never mind. I figured it out.
    I can use:

    pack("H*", "0123456789abcdef");

    For some reason, this works. I was
    initially trying to use pack("H8", ...)
    but for some reason that didn't work.

    So now I can pack with pack and unpack
    with bin2hex.

    Thanks

Similar Threads

  1. converting a string to an int
    By E_bored in forum C Programming
    Replies: 8
    Last Post: February 10th, 2004, 02:35 PM
  2. array explode ( string separator, string string [, int limit])
    By beemee_freeserv in forum HTML Programming
    Replies: 4
    Last Post: February 5th, 2004, 10:56 AM
  3. Replies: 7
    Last Post: January 16th, 2004, 05:44 AM
  4. Format hex byte to binary in C++
    By cheungtmk in forum C Programming
    Replies: 2
    Last Post: December 12th, 2003, 03:14 PM
  5. Is it possible to write hex into a binary file?
    By XFox Prower in forum PHP Development
    Replies: 2
    Last Post: November 25th, 2003, 12:20 AM

IMN logo majestic logo threadwatch logo seochat tools logo