Binary: Difference between revisions

From Data Crystal
Jump to navigation Jump to search
No edit summary
No edit summary
Line 1: Line 1:
'''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 [[#Bit|bits]] each. For example, the [[Super Nintendo:Color|SNES color]] format consists of fives bits for each of the red, green, and blue color components in a [[#Word|word]].


{{moreinfo wikipedia|page=binary}}
== Terminology ==
=== Bit ===
Each digit in a binary number is referred to as a '''bit'''.
{{moreinfo wikipedia|page=bit}}
=== Nybble ===
A '''nybble''' or '''nibble''' is a group of four [[#Bit|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 [[#Bit|bits]]. This is the smallest grouping which most computers can work with directly. Some formats may involve smaller divisions like the [[Super Nintendo:Color|SNES color]] format mentioned above, but special code must be used to deal with this.
{{moreinfo wikipedia|page=byte}}
=== 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 [[#Bit|bits]] (two [[#Byte|bytes]]), 32 bits (four bytes) or 64 bits (8 bytes). For example, a word on a [[Nintendo Game Boy Advance|GBA]] is 32 bits, whereas on a [[Nintendo Entertainment System|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.
{{moreinfo wikipedia|page=Word_(computer_science)}}
== 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 ==
* [[Hexadecimal]]
* [[Decimal]]
* [[Endianness]]
== External Links ==
* [http://www.mistupid.com/computers/binaryconv.htm Online converter] between binary and decimal
{{stub}}

Revision as of 15:59, 30 October 2005