# Convert program to binary

Tags:
1. Apr 9, 2015

### Steven Ellet

If I have program X how do I get it in binary form?

2. Apr 9, 2015

### Staff: Mentor

What do you mean by "program"? Is it source code of some kind? If so, what programming language? Some programming languages, such as C, C++, Fortran, and others require the use of a compiler and linker to translate the human-readable source code into machine code (i.e. a binary) that can run on a computer.
"Program" could also refer to an executable, in which case it is already in binary form.

3. Apr 10, 2015

### rcgldr

In the case of binaries for embedded X86 programs, there are variations of EXE2BIN that convert a .EXE file into a binary file (the addresses / offsets for the segments are passed in a parameter file or as command line parameters). The tool sets for other embedded processors, like the ARM, also include utilities for producing binary files (in some cases the linker is able to produce a binary file, similar to producing a X86 .COM file).

4. Apr 11, 2015

### Steven Ellet

Based on you response, it seems I have much to learn. When I say "Program" I mean quite a few things from executable to text documents to chrome, etc - but to start with, something simple. You say an executable is already in binary and yet it is a exe file, I am looking for the 01100 format. i am hoping for a program that can convert for me

5. Apr 11, 2015

### Staff: Mentor

Text documents are just that - text that is readable by humans. They are not binary files.
An exe file is in binary form. The exe2bin tool that rcgldr referred to existed back in the days of DOS. That tool was used to convert an exe file to a different format (but still binary) -- for the exe2bin that I'm referring to, see http://en.wikipedia.org/wiki/Exe2bin.
Convert what to binary form? There's no point in converting a text file to binary, and executables already are in binary form. Your question is still unclear.

6. Apr 11, 2015

### rootone

Any file consists of a sting of bytes
The bytes in an executable file represnt instructions and data that already have been been formatted in a way that the machine is able to use directly in performing whatever the task of the program is.
A text file is also a sting of bytes, but in that case the bytes are formatted in a way that that they could make sense to a human..
Program source files are text files and compilers are a tool which converts the human readable text into an executable that the machine can process.

However, any file is just a string of bytes, and any string of bytes whatever it's intended purposes is, can be viewed or edited as binary if there is a reason to do so.
You could convert this message into a binary form, though there wouldn't be any good reason to do it.
Binary is just a way of representing values and symbols, text is an other way, and there are other methods of representing values.
Binary is just a way representing values in a way that makes computation simple for a digital machine.

7. Apr 11, 2015

### Tosh5457

Anything in a computer is in binary code, text or otherwise. The difference between a simple text file and executables/libraries/drivers is that the binary/hex code of the text file is limited to ASCII codes (http://www.asciitable.com/), whereas executable files may have any hex codes. Download an Hex Editor, it'll show you the hex codes of any file, which you can then translate to binary using this tool for example: http://www.binaryhexconverter.com/hex-to-binary-converter

8. Jun 28, 2015

### Steven Ellet

Thank you, I had almost given up hope of being understood. This seems to be what I was looking for, even if it is not a program. Mark44-you did not understand my request, as Tosh5457 stated "Anything in a computer is in binary code, text or otherwise." hence "01100 format" Now that an understanding has been made, is there a program that will shortcut this process?

9. Jun 28, 2015

### Staff: Mentor

10. Jun 28, 2015

### DrZoidberg

So you want a program that takes an arbitrary file and converts it into a .txt file that contains a bunch of 1s and 0s?
What would you prefer? A linux command? Or maybe a C, Java or Python program?
There exists a linux program/command that can do this. It's called xxd.
Under linux you just open a console and type "xxd - b filename > output.txt".

11. Jun 28, 2015

### Staff: Mentor

Ha! I learn something new every day here, even after all these years.

Minor correction: no space between - and b:

xxd -b filename > output.txt

Omit the "> output.txt" and the results are displayed directly on the console. Mac OS has this available at the command line in the Terminal application:

Code (Text):

jtbell-iMac:Desktop jtbell$cat testfile One two three Four five six jtbell-iMac:Desktop jtbell$ xxd -b testfile
0000000: 01001111 01101110 01100101 00100000 01110100 01110111  One tw
0000006: 01101111 00100000 01110100 01101000 01110010 01100101  o thre
000000c: 01100101 00001010 01000110 01101111 01110101 01110010  e.Four
0000012: 00100000 01100110 01101001 01110110 01100101 00100000   five
0000018: 01110011 01101001 01111000 00001010                    six.

12. Jun 28, 2015

### phinds

Yes, all things in a digital computer are in binary form, but at first you were calling everything "programs" and that is what confused people. I think Mark understood your original post as well as it possibly COULD be understood since you clearly did not understand that text files, as you now know, are not programs.

13. Jun 30, 2015

### Steven Ellet

The Hex Editor program (HxD) I downloaded works great but does half the work I need-the output is in hex. No program or website seem able to handle the code properly, http://www.binaryhexconverter.com/hex-to-binary-converter has a max of max. 7fffffffffffffff and just results in an error. One example of what won't work has code that is (Hex) 00000000 through 0000F380 and 00 through 0F

Last edited by a moderator: Jun 30, 2015
14. Jun 30, 2015

### Staff: Mentor

15. Jun 30, 2015

### phinds

What is your actual goal here? I mean, hex IS binary, just condensed but trivial to read as binary, so what is it that a binary output will give you that a hex output won't?

Last edited by a moderator: Jun 30, 2015
16. Jun 30, 2015

### TheDemx27

17. Jun 30, 2015

### DrZoidberg

Could you be more specific? What exactly is that "code" that you want to convert to binary? What exactly is the binary output supposed to look like? And what do you want to use that binary code for?

18. Jun 30, 2015

### rcgldr

Maybe it was changed, but the wikipedia article for exe2bin now refers to the version that "existed back in the days of DOS". As mentioned in the wiki article, one usage for exe2bin was to create a .COM image file, and another usage was to create a binary file to be used in a BIOS or device driver. Variations of exe2bin were made to create images for embedded systems, although I'm not sure how this differs much from creating an image to be used in a BIOS. One aspect of this is that initialized data is stored somewhere in the image, and at startup, that data is moved from the stored location in the image to it's targeted location somewhere in read/write memory.

19. Jun 30, 2015

### Staff: Mentor

I'm with @phinds and @DrZoidberg here. @Steven Ellet, just what are you looking to do? It's a simple matter to convert from hex to binary (i.e., base-2). Just convert each hex digit to its equivalent four binary digits.
$$\begin{bmatrix} \text{hex} & \text{binary} \\ 0 & 0000\\ 1 & 0001\\ 2 & 0010\\ 3 & 0011\\ 4 & 0100 \\ 5 & 0101 \\ 6 & 0110 \\ 7 & 0111 \\ 8 & 1000 \\ 9 & 1001 \\ \text{A} & 1010 \\ \text{B} & 1011 \\ \text{C} & 1100 \\ \text{D} & 1101 \\ \text{E} & 1110 \\ \text{F} & 1111 \end{bmatrix}$$

20. Jun 30, 2015