Binary: Difference between revisions

From Data Crystal
Jump to navigation Jump to search
No edit summary
 
(11 intermediate revisions by 9 users not shown)
Line 31: Line 31:
=== Converting a Decimal Value to a Binary Value ===
=== Converting a Decimal Value to a Binary Value ===


Although many rom hackers can do this conversion in their head, it is very important for all of us to be able to convert decimal values to binary values.
It is useful to be able to convert between binary and decimal. When this calculation cannot be carried out mentally, there are simple methods of making the conversion on paper. Many operating systems also include a calculator which can convert between binary and decimal.


This can be done manually or using a calculator like Windows Calculator.
Please note that this method does not cover floating point decimals, which are rare in ROM hacking.
 
Please note that this method does not cover floating point decimals, which are rare in ROM hackering.
 
==== Using Paper and Pencil ====


First, write the following table on any piece of paper:
First, write the following table on any piece of paper:


|2^7 | 2^6 | 2^5 | 2^4 | 2^3 | 2^2 | 2^1 | 2^0
| 2^7 | 2^6 | 2^5 | 2^4 | 2^3 | 2^2 | 2^1 | 2^0


Then under the 2^7, write the non-exponential eqivalent, 128. Repeat for all of them. (Remember that 2^0 = 1).
Then under the ''2^7'', write the non-exponential eqivalent, ''128''. Repeat for all of them, remembering that ''2^0'' is ''1''.


Now, the process is very simple. Just pick the decimal value you want to convert. Start from the left of the table. Now ask yourself, "If I take my number and take away 2^7 (128) from it, will it still be a positive number?". If that's a yes, then do the subtraction and mark a "1" under the "2^7" on the table. Now, save the result from the previous subtraction and ask the same question to the next exponential "2^6 = 64". If it's true, then write another "1" in the table. If, by any chance, you get to a number where you cannot do the subtraction without getting a negative number as the answer, just write a 0 on the table and go on to the next number. When you are done with "2^0 = 1" then, you're all done!!! Results of DEC to BIN conversions:
Now, the process is very simple. First, pick the decimal value you want to convert. Start from the left of the table. Now ask yourself, "If I take my number and take away 2^7 (128) from it, will it still be a positive number?" If yes, then do the subtraction and mark a ''1'' under the ''2^7'' on the table. Now, save the result from the previous subtraction and ask the same question to the next exponential ''2^6 = 64''. If it's true, then write another ''1'' in the table. If, by any chance, you get to a number where you cannot do the subtraction without getting a negative number as the answer, just write a 0 on the table and go on to the next number. When you are done with ''2^0 = 1'', you are all done. Results of DEC to BIN conversions:


In the following examples, note that if the number on the table is 0, then you do not count its exponential towards the final sum.
In the following examples, note that if the number on the table is 0, then you do not count its exponential towards the final sum.


DEC - 217
DEC - 217
BIN - 11011001 (128 + 64 + 0 + 16 + 8 + 0 + 0 + 1)
BIN - 11011001 (128 + 64 + 0 + 16 + 8 + 0 + 0 + 1)
 
DEC - 128
BIN - 10000000 (128 + 0 + 0 + 0 + 0 + 0 + 0 + 0)


DEC - 127
DEC - 128
BIN - 01111111 (0 + 64 + 32 + 16 + 8 + 4 + 2 + 1)
BIN - 10000000 (128 + 0 + 0 + 0 + 0 + 0 + 0 + 0)


Simple, huh???
DEC - 127
BIN - 01111111 (0 + 64 + 32 + 16 + 8 + 4 + 2 + 1)


==== Using the Windows Calculator ====
== See also ==
 
Coming Soon...
 
== See Also ==


* [[Hexadecimal]]
* [[Hexadecimal]]
* [[Decimal]]
* [[Decimal]]
* [[Endianness]]
* [[Endianness]]
== External links ==
* [http://www.binaryhexconverter.com/binary-to-decimal-converter convert binary to decimal]
* [http://www.unit-conversion.info/texttools/convert-text-to-binary/ Convert text to binary]


{{stub}}
{{stub}}
[[de:Binär]]

Latest revision as of 19:10, 28 January 2024

Binary or base 2 is the number system used natively by computers. It uses only the digits 0 and 1. It is useful in ROM hacking especially when a value actually consists of multiple values, which do not take a multiple of eight bits each. For example, the SNES color format consists of fives bits for each of the red, green, and blue color components in a word.

More non-ROM hacking specific information can be found at Wikipedia's binary article.

Terminology

Bit

Each digit in a binary number is referred to as a bit.

More non-ROM hacking specific information can be found at Wikipedia's bit article.

Nybble

A nybble or nibble is a group of four bits. Most computers cannot read or write single nybbles, but they are notable since every hexadecimal digit represents exactly one nybble.

Byte

A byte is a group of eight bits. This is the smallest grouping which most computers can work with directly. Some formats may involve smaller divisions like the SNES color format mentioned above, but special code must be used to deal with this.

More non-ROM hacking specific information can be found at Wikipedia's byte article.

Word

A word is the natural unit of data for a given architecture. Unlike the previous terms, the size of a word varies from system to system. A word is usually a power of two time the size of a byte - generally 16 bits (two bytes), 32 bits (four bytes) or 64 bits (8 bytes). For example, a word on a GBA is 32 bits, whereas on a NES it is 16 bits. The order of these bits depends on the endianness of the machine. From this term, comes halfword (hword), for a unit of data half of the word size, double word (dword) for double the word size and quadruple word (qword) for eight times the word size.

More non-ROM hacking specific information can be found at Wikipedia's Word_(computer_science) article.

Working With Binary Values

Converting a Decimal Value to a Binary Value

It is useful to be able to convert between binary and decimal. When this calculation cannot be carried out mentally, there are simple methods of making the conversion on paper. Many operating systems also include a calculator which can convert between binary and decimal.

Please note that this method does not cover floating point decimals, which are rare in ROM hacking.

First, write the following table on any piece of paper:

| 2^7 | 2^6 | 2^5 | 2^4 | 2^3 | 2^2 | 2^1 | 2^0

Then under the 2^7, write the non-exponential eqivalent, 128. Repeat for all of them, remembering that 2^0 is 1.

Now, the process is very simple. First, pick the decimal value you want to convert. Start from the left of the table. Now ask yourself, "If I take my number and take away 2^7 (128) from it, will it still be a positive number?" If yes, then do the subtraction and mark a 1 under the 2^7 on the table. Now, save the result from the previous subtraction and ask the same question to the next exponential 2^6 = 64. If it's true, then write another 1 in the table. If, by any chance, you get to a number where you cannot do the subtraction without getting a negative number as the answer, just write a 0 on the table and go on to the next number. When you are done with 2^0 = 1, you are all done. Results of DEC to BIN conversions:

In the following examples, note that if the number on the table is 0, then you do not count its exponential towards the final sum.

DEC - 217
BIN - 11011001 (128 + 64 + 0 + 16 + 8 + 0 + 0 + 1)
DEC - 128
BIN - 10000000 (128 + 0 + 0 + 0 + 0 + 0 + 0 + 0)
DEC - 127
BIN - 01111111 (0 + 64 + 32 + 16 + 8 + 4 + 2 + 1)

See also

External links


So very stubbly.
This page is rather stubbly and could use some expansion.
Are you a bad enough dude to rescue this article?