SitePoint Sponsor

User Tag List

Results 1 to 7 of 7

Thread: Hex problem

Hybrid View

  1. #1
    SitePoint Zealot
    Join Date
    Jan 2013
    Posts
    110
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Hex problem

    hye guys, i have a .txt file which contain hex value such as F5/01/00/01/00/03/00/F5 (03 nad 01 appear as boxes in text file), and i wanted to take this value into php and convert it into binary. is it possible?

  2. #2
    SitePoint Guru bronze trophy TomB's Avatar
    Join Date
    Oct 2005
    Location
    Milton Keynes, UK
    Posts
    988
    Mentioned
    9 Post(s)
    Tagged
    2 Thread(s)
    Is the string actually the hex string?
    e.g.
    "F5010001000300F5" ?

    My first question, is why store it in this format? Store the binary and safe a lot of work/effort?

  3. #3
    SitePoint Zealot
    Join Date
    Jan 2013
    Posts
    110
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Quote Originally Posted by TomB View Post
    Is the string actually the hex string?
    e.g.
    "F5010001000300F5" ?

    My first question, is why store it in this format? Store the binary and safe a lot of work/effort?
    it actually an output from a device,i just transfer it to a file.

  4. #4
    SitePoint Guru bronze trophy TomB's Avatar
    Join Date
    Oct 2005
    Location
    Milton Keynes, UK
    Posts
    988
    Mentioned
    9 Post(s)
    Tagged
    2 Thread(s)
    Have you tried:

    PHP Code:
    $binary hex2bin(file_get_contents('file.txt)); 
    or:

    PHP Code:
    $binary pack('H*' file_get_contents('file.txt)); 

  5. #5
    SitePoint Zealot
    Join Date
    Jan 2013
    Posts
    110
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Quote Originally Posted by TomB View Post
    Have you tried:

    PHP Code:
    $binary hex2bin(file_get_contents('file.txt)); 
    or:

    PHP Code:
    $binary pack('H*' file_get_contents('file.txt)); 
    tried already..but still can't..i use this code below

    PHP Code:
    $contents file_get_contents('output.txt'); 
    echo 
    $contents
    and the output is . thats F5F5F5F5F5F5F5 in ISO-8859-1 format..why is that?

  6. #6
    SitePoint Guru bronze trophy TomB's Avatar
    Join Date
    Oct 2005
    Location
    Milton Keynes, UK
    Posts
    988
    Mentioned
    9 Post(s)
    Tagged
    2 Thread(s)
    Can you paste the exact contents of output.txt or at least the first few hundred bytes.

  7. #7
    SitePoint Zealot
    Join Date
    Jan 2013
    Posts
    110
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Quote Originally Posted by TomB View Post
    Can you paste the exact contents of output.txt or at least the first few hundred bytes.
    u can go to this link and see the picture. http://ubuntuforums.org/showthread.php?t=2133190 its inside the thread.


Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •