Jump to content

Converting a file to binary 1's and 0's


thisismyurl

Recommended Posts

Hi all, this may be a silly question but I'm trying to convert a file to a string of 1's and 0's but I keep getting stuck.

 

$n =  123456;

printf("%%b = '%b'\n", $n);

 

and get %b = '11110001001000000'

 

but when I try

 

$n =  "hello";

printf("%%b = '%b'\n", $n);

 

I get %b = '0'

 

What I'm trying to do is load a JPG and store it as '11110001001000000 ...'

 

If I load the file like this:

 

$file = file('test.jpg',FILE_BINARY);

foreach ($file as $line) {

  $totalfile .= $line;

}

 

Is there a way for me to convert $totalfile to a binary string like '11110001001000000 ...' ?

Link to comment
https://forums.phpfreaks.com/topic/175507-converting-a-file-to-binary-1s-and-0s/
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.