Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Difference between machine language, binary code and a binary file

I'm studying programming and in many sources I see the concepts: "machine language", "binary code" and "binary file". The distinction between these three is unclear to me, because according to my understanding machine language means the raw language that a computer can understand i.e. sequences of 0s and 1s.

Now if machine language is a sequence of 0s and 1s and binary code is also a sequence of 0s and 1s then does machine language = binary code?

What about binary file? What really is a binary file? To me the word "binary file" means a file, which consists of binary code. So for example, if my file was:

010010101010010
010010100110100
010101100111010
010101010101011
010101010100101
010101010010111

Would this be a binary file? If I google binary file and see Wikipedia I see this example picture of binary file which confuses me (it's not in binary?....)

Hex image

Where is my confusion happening? Am I mixing file encoding here or what? If I were to ask one to SHOW me what is machine language, binary code and binary file, what would they be? =) I guess the distinction is too abstract to me.

Thnx for any help! =)

UPDATE:

In Python for example, there is one phrase in a file I/O tutorial, which I don't understand: Opens a file for reading only in binary format. What does reading a file in binary format mean?

like image 723
jjepsuomi Avatar asked Feb 05 '14 08:02

jjepsuomi


People also ask

Is machine language the same as binary?

Machine code, also known as machine language, is the elemental language of computers. It is read by the computer's central processing unit (CPU), is composed of digital binary numbers and looks like a very long sequence of zeros and ones.

What is binary code in machine language?

binary code, code used in digital computers, based on a binary number system in which there are only two possible states, off and on, usually symbolized by 0 and 1.

What is the difference between codes and machine codes?

Both of these are codes that act as a set of instructions that help machines/ devices behave in a specified manner or perform certain operations/ tasks. The primary difference between byte code and machine code is that bytecode is an intermediate code while the machine code is the final code that the CPU processes.


3 Answers

Machine code and binary are the same - a number system with base 2 - either a 1 or 0. But machine code can also be expressed in hex-format (hexadecimal) - a number system with base 16. The binary system and hex are very interrelated with each other, its easy to convert from binary to hex and convert back from hex to binary. And because hex is much more readable and useful than binary - it's often used and shown. For instance in the picture above in your question -uses hex-numbers!

Let say you have the binary sequence 1001111000001010 - it can easily be converted to hex by grouping in blocks - each block consisting of four bits.

 1001 1110 0000 1010 => 9  14 0 10 which in hex becomes: 9E0A.  

One can agree that 9E0A is much more readable than the binary - and hex is what you see in the image.

like image 151
Björn Hallström Avatar answered Oct 03 '22 21:10

Björn Hallström


I'm honestly surprised to not see the information I was looking for, looking back though, I guess the title of this thread isn't fully appropriate to the question the OP was asking.

You guys all say "Machine Code is a bunch of numbers".

Sure, the "CODE" is a bunch of numbers, but what people are wondering (I'm guessing) is "what actually is happening physically?"

I'm quite a novice when it comes to programming, but I understand enough to feel confident in 'roughly' answering this question.

Machine code, to the actual circuitry, isn't numbers or values. Machine code is a bunch of voltage gates that are either open or closed, and depending on what they're connected to, a certain light will flicker at a certain time etc.

I'm guessing that the "machine code" dictates the pathway and timing for specific electrical signals that will travel to reach their overall destination.

So for 010101, 3 voltage gates are closed (The 0's), 3 are open (The 1's)

I know I'm close to the right answer here, but I also know it's much more sophisticated - because I can imagine that which I don't know.

010101 would be easy instructions for a simple circuit, but what I can't begin to fathom is how a complex computer processes all of the information.

So I guess let's break it down?

x-Bit-processors tell how many bits the processor can process at once.

A bit is either 1 or 0, "On" or "Off", "Open" or "Closed"

so 32-bit processors process "10101010 10101010 10101010 10101010" - this many bits at once.

A processor is an "integrated circuit", which is like a compact circuit board, containing resistors/capacitors/transistors and some memory. I'm not sure if processors have resistors but I know you'll usually find a ton of them located around the actual processor on the circuit board

Anyways, a transistor is a switch so if it receives a 1, it sends current in one direction, or if it receives a 0, it'll send current in a different direction... (or something like that)

So I imagine that as machine code goes... the segment of code the processor receives changes the voltage channels in such a way that it sends a signal to another part of the computer (why do you think processors have so many pins?), probably another integrated circuit more specialized to a specific task. That integrated circuit then receives a chunk of code, let's say 2 to 4 bits 01 or 1100 or something, which further defines where the final destination of the signal will end up, which might be straight back to the processor, or possibly to some output device.

Machine code is a very efficient way of taking a circuit and connecting it to a lightbulb, and then taking that lightbulb out of the circuit and switching the circuit over to a different lightbulb

Memory in a computer is highly necessary because otherwise to get your computer to do anything, you would need to type out everything (in machine code). Instead, all of the 1's and 0's are stored inside some storage device, either a spinning hard disk with a magnetic head pin that 'reads' 1's or 0's based on the charge of the disk, or a flash memory device that uses a series of transistors, where sending a voltage through elicits 1's and 0's (I'm not fully aware how flash memory works)

Fortunately, someone took the time to think up a different base number system for programming (hex), and a way to compile those numbers (translate them) back into binary. And then all software programs have branched out from there.

Each key on the keyboard creates a specific signal in binary that translates to a bunch of switches being turned on or off using certain voltages, so that a current could be run through the specific individual pixels on your screen that create "1" or "0" or "F", or all the characters of this post.

So I wonder, how does a program 'program', or 'make' the computer 'do' something... Rather, how does a compiler compile a program of a code different from binary? It's hard to think about now because I'm extremely tired (so I won't try) but also because EVERYTHING you do on a computer is because of some program. There are actively running programs (processes) in task manager. These keep your computer screen looking the way you've become accustomed, and also allow for the screen to be manipulated as if to say the pictures on the screen were real-life objects. (They aren't, they're just pictures, even your mouse cursor) (Ok I'm done. enough editing and elongating my thoughts, it's time for bed)

Also, what I don't really get is how 0's are 'read' by the computer. It seems that a '0' must not be a 'lack of voltage', rather, it must be some other type of signal Where perhaps something like 1 volt = 1, and 0.5 volts = 0. Some distinguishable difference between currents in a circuit that would still send a signal, but could be the difference between opening and closing a specific circuit.

If I'm close to right about any of this, serious props to the computer engineers of the world, the level of sophistication is mouthwatering. I hope to know everything about technology someday. For now I'm just trying to get through arduino.

Lastly... something I've wondered about... would it even be possible to program today's computers without the use of another computer?

like image 34
Viriality Avatar answered Oct 03 '22 23:10

Viriality


Machine language is a low-level programming language that generally consists entirely of numbers. Because they are just numbers, they can be viewed in binary, octal, decimal, hexadecimal, or any other way. Dave4723 gave a more thorough explanation in his answer.

Binary code is basically any information represented by a sequence of 1s and 0s.

A binary file is any non-text file; e.g. an .exe, a .png, etc.

like image 45
The Guy with The Hat Avatar answered Oct 03 '22 21:10

The Guy with The Hat