Can I program in Binary?

Pages: 12
Hello dear members

Before asking anything I want to say, I searched a lot of sites and forums but all in vain, so please give me a perfect answer.Some of them say you can and others say you can't program in binary.

I want to program in binary language, just in binary nothing more.
I know it Could be very very difficult, but i like to have experience in how to program in binary even if it is adding two numbers together.If it's impossible, so how did they program for the very first time?
How did they create the first compiler?
So I want the name of the binary compiler
Don't recommend HexEditor, I like to program in binary not assembly language nor in hexadecimal.
Thanks.
http://stackoverflow.com/questions/4197055/can-i-write-a-program-in-binary-directly-how-can-i-get-the-computer-to-execute

Binary ain't compiled - it's as low as it gets. You'd need to use a hex editor, I believe.
It's possible. There's just very little point nowadays. Writing a whole program in machine language is time consuming, difficult, has minimal advantages, and forever locks your code to the particular machine you wrote it for.
The few people who still develop in machine language only write specific parts of a program (other parts being written in a HLL) and in Assembly, not hexadecimal, let alone binary.

how did they program for the very first time?
1. Early computers were very simple by today's standards. Their I/O capabilities were very limited. The very early ones did not have an OS and simply executed a single program at a time. Doing anything remotely useful now involves interacting with system libraries, which itself involves a lot of boilerplate code to prepare calls. If you're using an HLL the compiler does this for you, but if you use machine language you have no choice but to do it yourself.
2. They were also designed to be programmed directly, with instruction sets that accommodated machine code generated by humans. Modern CPUs are not only designed to be programmed primarily by machines, with few convenience instructions, but are even optimized to perform machine-generated use patterns more quickly.

Don't recommend HexEditor, I like to program in binary not assembly language nor in hexadecimal.
I have to ask: do you want to do this because you're legitimately curious, or because you want to brag to your friends about how you code in binary?
Writing a preprocessor that takes a text file filled with 1s and 0s and outputs an actual binary file is trivial, so knock yourself out.
This is regression..
I think you should learn assembly first. The program that translates assembly code into machine code is called an assembler. It's like an compiler but much much simpler. There is much less magic going on so there will be close to a 1-to-1 mapping between the assembly that you write and the machine code.

If you was to write the machine code directly without using an assembly language you would still have to think in the terms of an assembly language inside your head. PUSH, POP, CMP, JMP, etc. It would just be much more work because you would have to look up what different numbers mean all the time.

You say you don't want to use an hex editor, then what do you want to use? Do you want to build your own computers through wires and stuff like that. Well, I can't help you with that because I know too little about it. If you just want to enter values as zeroes and ones you should know that many hex editors will allow you to do that.
Ok
I am not bragging,but I am curious about how this task can be done just in binary.
For example, write two numbers (101 & 100) to a file or into a particular assembler and that file or assembler add these two numbers together and give me the result of 9. Something like that. I think that is not impossible. If it's impossible, so how was the first assembly language built when unable to program in binary. I don't want to program in binary,. but I like to know the idea behind that.
Thx a lot .........................................................................................................................
For example, write two numbers (101 & 100) to a file or into a particular assembler and that file or assembler add these two numbers together and give me the result of 9.
I'm going to try to interpret this in a way that makes some sense.
"Write a small piece of code that adds the numbers 5 and 4."
Yes, it's possible. In x86 Assembly:
1
2
3
4
mov eax, 5
mov ebx, 4
add eax, ebx
; result in eax

In hex (parsed):
66B8 05000000
66BB 04000000
6601D8

In stupid binary:
; mov eax, 5
01100110
10111000
00000100
00000000
00000000
00000000

; mov ebx, 4
01100110
10111011
00000101
00000000
00000000
00000000

; add eax, ebx
01100110
00000001
11011000

Hopefully this shows why binary is not used, even when directly writing the opcodes.
Lets start from very beginning. Deep inside computers store everything as numbers, even programs. They can interpret numbers as commands. For example, number 5 might mean "add two numbers from following locations and store result in register1", following 3 might mean register3 and next 12 means "number at memory adress described by next four bytes". This is how processors operate.

Early on computers were dumb, and lacked many things, like keyboard and OS. Programs were been fed through perfocards: pieces of paper with holes in them. No hole in specific place = 1, hole = 0. So if you wanted to add 2 numbers you would punch number five in binary on card (hole - hole - hole - hole - hole- no hole - hole - no hole) and then continue with other commands (what the arguments are and so on).

Later most people started using hex notation to write commands: it was easier to read and harder to misread. Perfocards were punched in binary, but not manually: there were special mechanical punchers with keyboards from 0 to F punching 4 holes at a time allowing easy and fast preparing of perfocards.

When other input methods were created (like keyboards), people started to write programs directly in memory: write sequence of commands in editor, save file and execute it. It was easier.

Some people wanted to write something like add reg1 mem[0F62] instead of 03050C0F62. They have created first assembler. It was a dumb thing which just replaced one sequence of characters with others (add 0x03, etc.). Later, things like labels, which allowed recalculation of specific code addresses to happen automatically (I do not want to look through resulting binary, see where beginning of my function is and write that adress instead of dummy one in place of call manually), data section (just stick that sequence of bytes somewhere and let me refer to it) and other stuff.

Still assembler is very close to hardware. It just allows for easy mnemonics (add is easier to remember than 03, right?) and to automate some stuff (like adress calculation).

Last edited on
Technically, no you can't program in binary. There is no such computer language. If you want USE binary inputs and outputs to encode machine specific instructions and data to a particular type of physical CPU then yes you can do that but you will still be programming in that CPUs machine language. You can also build your own computer from scratch out of vacuum tubes and magnetic cores but I wouldn't suggest that either.

If you are REALLY curious and want to learn about the basic fundamentals that all modern computers are based on well GOOD FOR YOU! Check out the good old Altair 8800:
https://en.wikipedia.org/wiki/Altair_8800
You can find emulators to simulate the 8800 allowing you to use a virtual monitor or even buy a real 8800 front panel with LEDs and toggle switches (it's USB!).

But the bottom line is that you'll be "programming" in a machine language written to work with a specific CPU chip, not binary.

And remember: There are only 10 kinds of people who understand binary. 8^D
at least try assembly using an IDE like masm or tasm , but if you really want to do binary , write a print in console in asm then convert it in binary and save it in a exe file ..
Thanks a lot. Y'all
The other things you'll need to look into are (1) the format of an executable file on your system and (2) system calls to perform I/O. If you want to program directly in binary I suggest a very old machine running DOS, or maybe something like an Arduino because it both cases the exe format and system call for I/O is pretty easy.

I remember the PDP 11/40. It had toggle switches and LEDs on the front. You would set the toggles to an address and load the address. Then you could examine the data there (the LEDs would be on for 1, off for 0). You could also set the toggles and deposit new data into the address. Finally you could run starting at the address. There was a half-page printout that described how to load a program to boot the computer from the disk if all else failed. The program read sector 0 off the disk into memory and then jumped to it.

Oh, you might also look into an Altair 8800. This was the first personal computer.
You might also want to learn how BIOS operates. BIOS provides the basic interface for booting a PC and interacting with the hardware at a very low level. Most BIOSes today are written in assembler, but the assembly instructions have a direct binary representation meaningful to the hardware.

When the first IBM PC came out with an 8086 CPU, the first thing I did was to go out and buy a listing of IBM's BIOS to get a low level understanding of the hardware.

When I started in this business many years ago, I worked on CDC computers that had a bootstrap panel than consisted of about 20 rows of toggle switches. One row for each machine instruction required to boot the hardware. The number of toggle switches in a row depended on the word length of the particular machine. When the master reset (boot) switch was pressed, the machine started executing the bootstrap program from the toggle switch panel. While the toggle switches were set as binary instructions, they corresponded one for one to machine instructions. I used to know those bootstrap programs by heart, but it's been too long.


Yes That is true.
I guess, to understand how binary works, I should learn sth about a simple 4 bit calc or Altair 8800 or Ardunio and capacitors, transistors, how they work, how they store data, etc.............
Thanks 4 yr help.
What you need to understand is that binary is simply a representation of 0s and 1s.

That representation can mean any number of things:
- A integer number
- A floating point number
- One or more characters (ASCII, EBCDIC, Kanji, or other representation)
- A machine instruction
- A representation of a hardware register, such as an I/O controller status word
- A user defined bit representation of something (e.g. a C++ std::bitset)

You have to know what you're looking at to be able to interpret it correctly.
and capacitors, transistors, how they work, how they store data, etc

Don't get too lost in the details if your ultimate goal is to write programs. Most programmers haven't a clue how the hardware works at the transistor level. They don't need to.
Yes, but I think the most important thing in computer field is,Knowing the basics of hardware, how can hardware understand letters, numbers and symbols.
If you just memorize the languages or libraries of a language without understanding binary and how computers work, is worth nothing and you don'k know what's going on inside it ant it will be kinda useless.But if you know hardware stuff,you can solve everything and implement things later on.
If you just memorize the languages or libraries of a language without understanding binary and how computers work, is worth nothing and you don'k know what's going on inside it ant it will be kinda useless.
You are incorrect. While an understanding of the low level details of the platform are useful to produce efficient programs, they are not essential to do this, and they are certainly not required to produce correct programs. Programming is about getting an abstract machine to do something useful. The concrete machine that implements the abstract machine is generally an implementation detail.
The concrete machine that implements the abstract machine is generally an implementation detail.
While this is usually true, sometimes knowledge of the hardware can help discover a performance problem. An example I've seen several times is scanning through columns of a 2D array. It works fine until the array gets large enough and then performance suddenly drops way off. The reason is the hardware.

Omer123, you can pursue these topics in parallel. From low level to high level, they are (roughly) physics, electronics, discreet math and logic, digital circuit design, computer architecture, programming, computer science.
simply keep in mind 0 & 1 ...
For hardware , look for specs . Depending on what you are working on , you might find some patterns .

You can try to investigate the number of cycles for a single instruction , etc.

Pages: 12