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

  • SEARCH
  • Home
  • 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 601167
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 13, 20262026-05-13T16:41:06+00:00 2026-05-13T16:41:06+00:00

How can I read the binary code(to get the 1s and 0s) of a

  • 0

How can I read the binary code(to get the 1s and 0s) of a file.

$filename = "something.mp3";
$handle = fopen($filename, "rb");
$contents = fread($handle, filesize($filename));
fclose($handle);

I tried this but it shows some strange characters… I presume that this is the formated binary? I was hoping to get the 1’s and 0’s instead.

Also I am not looking only .mp3 files it could be anything .e.g: .txt , .doc , .mp4, .php, .jpg, .png etc….

  • 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-13T16:41:07+00:00Added an answer on May 13, 2026 at 4:41 pm

    Files are stored on the computer in binary form indeed, but the 1s and 0s are stored together in groups of 8 (called bytes). Now, traditionally, each byte may be represented by an ASCII character because of the fact that there are 256 possible values that can be represented in a byte – which happens to coincide with the total number of different ASCII characters available (this was not a coincidence but actually by design).

    That being said, what you are getting back from the fread function is what you’re supposed to get: i.e. the contents of the file.

    If you want to see the 1s an 0s you will need to print each byte that your receive into it’s base 2 representation. You can achieve that using a function such as base_convert or by writing your own.

    $filename = "something.mp3";
    $handle = fopen($filename, "rb");
    $fsize = filesize($filename);
    $contents = fread($handle, $fsize);
    fclose($handle);
    
    // iterate through each byte in the contents
    for($i = 0; $i < $fsize; $i++)
    { 
       // get the current ASCII character representation of the current byte
       $asciiCharacter = $contents[$i];
       // get the base 10 value of the current characer
       $base10value = ord($asciiCharacter);
       // now convert that byte from base 10 to base 2 (i.e 01001010...)
       $base2representation = base_convert($base10value, 10, 2);
       // print the 0s and 1s
       echo($base2representation);
    }
    

    NOTE

    If you have a string of 1s and 0s (the base 2 representation of a character) you can convert it back to the character like so:

    $base2string = '01011010';
    $base10value = base_convert($base2string, 2, 10);  // => 132
    $ASCIICharacter = chr($base10value);               // => 'Z'
    echo($ASCIICharacter);                             // will print Z
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

How you can read a file (text or binary) from a batch file? There
I have binary data in a file that I can read into a byte
In Java you can read a file embedded inside a JAR-file by using the
Anyone can read the GoF book to learn what design patterns are and how
I can read the MySQL documentation and it's pretty clear. But, how does one
You can read about the 64-bit calling convention here . x64 functions are supposed
In .Net you can read a string value into another data type using either
For what I can read, it is used to dispatch a new thread in
This is a question you can read everywhere on the web with various answers:
I am wondering how I can read CSS comments out of a linked stylesheet.

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.