• 14
• 12
• 9
• 10
• 13

General Intrest Question On Binary

This topic is 4876 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.