Click here to Skip to main content
15,887,683 members
Please Sign up or sign in to vote.
3.00/5 (6 votes)
See more:
Hi,
May be this is a really silly question but can you please clarify to me as to why I cannot see 1's and 0's when I try opening an .exe file into a text editor or when I try to display the .exe using and file display command in any OS. But instead i see a lot of unknown or unwanted characters.

I know how a compiler works but i want the raw facts behind the compilation as to why the compilation process ultimately produces an exe.

If it is not worth to read a .exe file to a user then what is the purpose of producing it as a visibile file on the OS to the user. Instead the OS can hide the actual .exe and just throw a name to the invisible file for our usage.

I have asked this question to some of the senior developers(.Net and Java Developers) aswell, but they all end up saying that a compiler translates a user written source code to intermediate assembly instructions which we can open and see and finally the assembly instructions are translated into machine instructions(1's and 0's). But they could not explain why could I not see 1's and 0's in .exe file when i try to display the .exe file using various file content display commands.
Posted
Updated 13-Jun-12 10:09am
v2
Comments
Chris Losinger 13-Jun-12 16:12pm    
seriously?
[no name] 13-Jun-12 16:18pm    
Yes
Albert Holguin 13-Jun-12 19:05pm    
It's as easy as... The text editor assumes all these one and zeros are text and tries to interpret them, leading to gibberish...
Albert Holguin 13-Jun-12 19:07pm    
If your senior developers can't explain this.... Run.... Just run away from this job and never, ever go back...its not worth working there.

Well let's start with the most obvious problem, you opened it in a text editor. The text editor assumes anything you want opened in it is text, and is therefore showing you the equivalent text of the executable.

EVERY file on your computer is in 1's and 0's. All the time. It's how computers work. But those 1's and 0's are meaningless on their own, they need to be interpreted by something. Your text editor probably assumes the data is in ASCII format, and tries to display equivalent ASCII characters (e.g. 01000001 is agreed upon in the ASCII standard to mean 'A', so upon encountering that byte 'A' is displayed). Even in a text editor, the character 0 is represented by a whole byte (most commonly, it may be bigger), not just a single 0 in binary format, the same goes for 1. (For example in ASCII 0 is 00110000, and 00000000 is interpreted as a null character. Not at all the same.)

You'd need a special editor to do what you want (and even then, hexadecimal representation is favored over binary, for reasons I won't go into here).

Next, an .exe isn't a simple list of machine code instructions. There are sections for data, and other things (you can generally open an executable in something like 7zip and see some of the internal parts). Even exe's from .Net are in binary, just not machine code.

As for why the file is visible...well how else would you distribute it? How would I give you an .exe if I couldn't interact with the file? What if I need to move it, or delete it? And just giving a name to redirect to it...well on some level the OS does this with every file already (you'd have to read about file systems, it's too complicated to go into here).

I'm not sure what your goal is with this, but I'm pretty sure you're going about it the wrong way. I recommend you read Code[^], it's very accessible even to complete beginners, and will give you a very good sense of how it all works.
 
Share this answer
 
v2
Comments
[no name] 13-Jun-12 16:51pm    
It helped me a lot. Thank you :)
Nelek 13-Jun-12 19:01pm    
Nice explanation
Tim Corey 13-Jun-12 22:02pm    
Nice answer.
stib_markc 14-Jun-12 2:20am    
Excellent answer. 5!
Mohibur Rashid 14-Jun-12 21:58pm    
You deserve a five
Read this article Learning Binary and Hexadecimal[^]

I will refrain from adding any other comments.


Soren Madsen
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900