Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6361323
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 24, 20262026-05-24T23:45:48+00:00 2026-05-24T23:45:48+00:00

I had looked for a way to view a file as hex a while

  • 0

I had looked for a way to view a file as hex a while ago and found:

class Hex 
{ 

   var $file; 
   var $hex; 

   function __construct($file) 
   { 
      $this->file = $file; 
   } 


   function gethex() 
   { 
      $handle = fopen($this->file, 'r') or die('Permission?'); 

         while(!feof($handle)) 
         { 
            foreach(unpack('C*',fgets($handle)) as $dec) 
            { 
               $tmp = dechex($dec); 
               $this->hex[] .= strtoupper(str_repeat('0',2-strlen($tmp)).$tmp);    
            } 
         } 

      return join($this->hex); 
   } 

   function writehex($hexcode) 
   { 

      foreach(str_split($hexcode,2) as $hex) 
      { 
         $tmp .= pack('C*', hexdec($hex)); 
      } 

         $handle = fopen($this->file, 'w+') or die('Permission?'); 
         fwrite($handle, $tmp); 

   } 

} 

It worked great for one file, but I think I’m running into problems with trying to do it with multiple files. Is there anything wrong with the script? Should it close the files somewhere? Should I delete the instances of it after using them?

Would this be better?:

class Hex 
{ 

   var $file; 
   var $hex; 

   function __construct($file) 
   { 
      $this->file = $file; 
   } 


   function gethex() 
   { 
      $handle = fopen($this->file, 'r') or die('Permission?'); 

         while(!feof($handle)) 
         { 
            foreach(unpack('C*',fgets($handle)) as $dec) 
            { 
               $tmp = dechex($dec); 
               $this->hex[] .= strtoupper(str_repeat('0',2-strlen($tmp)).$tmp);    
            } 
         } 
      fclose($handle);
      return join($this->hex); 
   } 

   function writehex($hexcode) 
   { 

      foreach(str_split($hexcode,2) as $hex) 
      { 
         $tmp .= pack('C*', hexdec($hex)); 
      } 

         $handle = fopen($this->file, 'w+') or die('Permission?'); 
         fwrite($handle, $tmp); 
         fclose($handle);

   } 

} 
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-24T23:45:48+00:00Added an answer on May 24, 2026 at 11:45 pm

    I don’t see problems with multiple files with this script but it could become a problem when you do not close the file. Best would be to close the file before the end of the function/the return.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

We had a View Model that looked like this: public class myViewModel { public
I had a function based view that looked like this: def account_details(request, acc_id): account
I'm wondering the best way to approach this. I have a JavaScript file in
EDIT: it turned out this question had been asked the wrong way — see
I ran into a problem where I declared a function this way: struct my_struct
I had a bit of conditional code that looked like this: if self.above and
If I had an ASP.NET 4.0 DataView control that looked like below, how can
Has anyone looked at Yahoo's ASTRA ? It's fairly nifty, but I had some
Had a coworker ask me this, and in my brain befuddled state I didn't
I had an idea, if I add a python .py file to my C#

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.