# General Intrest Question On Binary

This topic is 4779 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

## Recommended Posts

I read up a bit on binary and binary addition ... but what i want to know is, how it works? What i mean is, i know the 1 stands for an on position and 0 for off. But what is on and off? Is it little switch's in thing's like micro-procecress or what? And how can you make binary files do what you want them to do. I know programming in binary has pritty much no use, but i'd like to have a basic idea. All i find googling is binary addition and things like that, but nothing about how to use it Any help/link/anything will be appreciated ;) Thanks :D

##### Share on other sites
all that depends, do you mean a bootable binary, or one that runs in a VM or OS?(the switches in the CPU are called transistors, btw)

##### Share on other sites
What your asking is "how do i write programs in binary". The binary numbers can be treated as just pure numbers, or as instructions to the processor.

Here's an example of a binary instruction:

1000000000000101

the left-most 4 didgets of the binary are the op-code. The remaining 12 bits are the memory address of what it is your going to be using.

so you can break it apart to visiually see it better

1000____000000000101
1000 is the opcode. It means "Jump"
000000000101 is the memory address. 101 = 5 decimal

You memorize the op-codes. The creators of the chip decide what numbers mean what action.
0001 means "store"
0010 means "clear"
It's different depending on what chip your programming.

This is why assembly language was made. Intead of typing out tedious 1's and 0's they could just type "JUMP label". That's much easier on your eyes.

Then languages were made that pushed you away from the memory locations and you could focus entirely on the algortihm. Like C++. Hope this helps.

##### Share on other sites
Eh, it will take ages. At least, go with assembly language; it is quite enough for low level purposes...

##### Share on other sites
And remeber. Machine language and assembly are not hard at all. Many people say assembly is horrible, but in reality it's no harder than C++. You can implement an algorithm thinking it through the exact same way you would using a higher level language. It's just people get so used to a partiular language they can't open their mind to realize that algorithms are no different whether you type:

goto label; in C++

or

JUMP label in assembly

or

1000000000000101 in binary

##### Share on other sites
Thanks for all the help ;)
I get what your saying and am gona give assembly a quick look at to get a better understanding of what binary can do ;)

##### Share on other sites
I was thinking what the best way to answer the OP's question and ended up with this, which is similar to the way the CPU adds integers together (i.e. all done with logical operations):
void adc (bool a, bool b, bool c, bool &sum, bool &carry_out){    sum = (!(!(a && b) && (a || b)) && c) || ((!(a && b) && (a || b)) && !c);    carry_out = ((a && b) && !c) || ((a || b) && c);}unsigned int add (unsigned int a, unsigned int b){    unsigned int        result = 0;    bool        c = false;    for (unsigned int mask = 1 ; mask ; mask <<= 1)    {        bool            sum;        adc (a & mask, b & mask, c, sum, c);        result |= sum ? mask : 0;    }    return result;}

Skizz

##### Share on other sites
If your programming in assembly, it helps to have a drawing or visual representation of the chip you are programming. And you can have a little square to represent each register. You can fill them in with values while your thinking and erase them, ect.

If your using an intel chip, you don't need the latest version since they are all backwards compatible. I think.

##### Share on other sites
Quote:
 Original post by mcgrane66But what is on and off?

Quote:
 And how can you make binary files do what you want them to do.

The files don't "do" anything except contain data. You give meaning to the patterns in the data, and process it. Information, you know.

Here's the big secret. ALL files are at the core "binary files". Some operating systems don't try to distinguish them from "text files". The ones that do (cough Windows) aren't doing much: calling something a "text file" just implies some conventions about what data marks the "end of a line", in some cases indicates that a certain character means "end of the file", and *implies* that the data will be human-readable if you open it up in a text editor. "binary files" often contain plenty of data that is human-readable, because there is no good reason to make it otherwise. "text files" sometimes aren't.

And this is nothing really to do with reading/writing a file in "text mode" or "binary mode"; you can switch the modes around just fine (although you probably don't want to. Then again, there is a decent argument to be made for always reading/writing in binary mode, but I don't really want to get into it.)

And that's nothing again to do with "programming in binary" (i.e. typing out the executable data directly).

Anyway. Giving meaning to raw data typically means having a 'format' for it. Browse around here for some examples of real-world file formats. Common things that you might note in "binary" formats (ones not meant to be human-readable) are:

- The file is often conceptually divided into "chunks", where each is prefaced with a few letters that indicate the "type of chunk", and a binary number indicating the "size of chunk". Often there will also be a "checksum" value at the end of each chunk.

- There is usually a "header" which is not necessarily formatted as a chunk, but contains more "meta" type information. E.g. for an image format, words X and Y of the header might contain the height and width of the image that's supposed to be represented.

- Sometimes chunks are designed so as to be able to contain other chunks, in a tree structure.

##### Share on other sites
The actual data in your processor is stored by having a simple(!) transister circuit that saturates at either a high or low voltage state. These circuits can be combined to create words and have useful "carry" properties.

have a look for flip-flops, D-Type latches and RS Latches. Its suprising how simple some of these logic concepts are, and yet they are so powerful...

##### Share on other sites
I guess if you want to understand what "Binary" really is, you need to go back to Math...(Err)

We are used to a base-10 system, such that a number 1234 means nothing but:

1* 10^3 + 2 * 10^2 + 3 * 10^1 + 4 * 10^0.

In this system, you need 10 symbols to represent all real numerical values.

If, however, we switch base to base two, we'll only have 2 symbols to play with (0 and 1), and thus we call this mathematical system "Binary".

So what is "1" then? It's merely a mathematical symbol that represents a value. It can be interpret as different things, of course. Since there is two numbers, virtually everything with only two states can be interpreted as "Binary". Such as TRUE and FALSE, HI and LO, ON and OFF, LEFT and RIGHT, etc.

In electrical engineering, there is something called Non Linear Gates, which says that it will output a voltage if the input voltage is high enough, otherwise there will be no voltage (or almost no). Such devices can be used to represent and manipulate the Binary system, with High Voltage denoting "1" and Low Voltage denoting "0".

Meanwhile there are magnetic storage devices which uses this idea combined with electromagnetism to store binary data.

You need not to understand in great detail how, down to the lowest level, these things work. However a general understanding of Binary mathematics is required if you ever intent to program something useful (well...you can argue over this but that's my opinion). Binary Operations also include Logical Operations such as AND\OR\XOR and NOT.

How to use it? Well that really depends on what you want to do with it. How do you exactly describe the use of the number "9"? It's worth while to note that all code you write is translated to BINARY INSTRUCTIONS at some point (often at compile time). Since electrical circuits can only manipulate binary numbers. You can refer to the previous replies about this topic :)

##### Share on other sites

This topic is 4779 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

## Create an account

Register a new account

• ### Forum Statistics

• Total Topics
628732
• Total Posts
2984437

• 25
• 11
• 10
• 16
• 14