Binary
.code
01010101 10001001 11100101 10000011 11101100 00001000 10000011 11100100 11110000 10111000 00000000 00000000 00000000 00000000 10000011 11000000 00001111 10000011 11000000 00001111 11000001 11101000 00000100 11000001 11100000 00000100 10001001 01000101 11111100 10001001 01000101 11111100 11101000 00011011 00000101 00000000 00000000 11101000 11010110 00000001 00000000 00000000 11000111 00000100 00100100 00000000 00110000 01000000 00000000 11101000 01110010 00000101 00000000 00000000 11001001 11000011
.data
01001001 00100000 01001100 01101111 01110110 01100101 00100000 01011001 01101111 01110101
Binary is a base-2 numeral counting system. The base-2 means that the binary number can be represented by two mutually exclusive states. These states can be for example either On or Off, as in the case of a light bulb. Each one and zero above represents one of those states. A simple way to think about the data above is to visualize 528 light bulbs in a row either off or on depending on their state.
Binary numbers can be used to represent integers (4,234,-6) rather than just being for a single one or zero state. For example, the first eight binary digits above 01010101 is equal to 85 in decimal (base-10 or using your fingers). Here is the classical arthritic for converting binary to decimal: [(0) × 2^7] + [(1) × 2^6] +[(0) × 2^5] + [(1) × 2^4] + [(0) × 2^3] + [(1) × 2^2] + [(0) × 2^1] + [(1) × 2^0] = 85. Basically what this means is that we can use ones and zeros to represent an infinite set of integers.
In the early years of computing, binary numbers were used to program in machine code. This is no longer the case.
Hexadecimal
.code
55 89 E5 83 EC 08 83 E4 F0 B8 00 00 00 00 83 C0 0F 83 C0 0F C1 E8 04 C1 E0 04 89 45 FC 89 45 FC E8 1B 05 00 00 E8 D6 01 00 00 C7 04 24 00 30 40
00 E8 72 05 00 00 C9 C3
.data
49 20 4C 6F 76 65 20 59 6F 75
Programming in binary (also called machine code) is an extremely tedious process. In order to simplify this process mnemonic codes were used rather than binary digits. Mneomic codes are helpful because they are closer to human language. Mneomic codes are represented in the numerical format of hexadecimal.
Hexadecimal is a base-16 numeral format. Rather than having two states as in the case of binary hexadecimal can have 16 states. The different states are represented by the digits 0,1,2,3,4...9,A,B,C,D,E,F. The digit 0xE equals 14 in decimal. Hexadecimal is easy for computers because 2 (on or off) to the power of 4 equals 16. Hexadecimal is visually easier to read than binary. 01010101 binary equals 55 hexadecimal.
Assembly Language
.code
PUSH EBP
MOV EBP,ESP
SUB ESP,8
AND ESP,FFFFFFF0
MOV EAX,0
ADD EAX,0F
ADD EAX,0F
SHR EAX,4
SHL EAX,4
MOV [LOCAL.1],EAX
MOV EAX,[LOCAL.1]
CALL love.00401820
CALL love.004014E0
MOV DWORD PTR SS:[ESP],love.00403000 ; |ASCII "I Love You."
CALL ; \printf
LEAVE
RETN
.data
I Love You.
Converting hexadecimal to mnemonics code is done by a disassembler. The instructions
"PUSH EBP"
equals 0x55.
When a disassembler converts hexadecimal to mnemonics code the output is assembly language. The hexadecimal has to be valid mnemonics code in order to be converted to assembly language. The hexadecimal to mnemonic code conversion is defined by what processor the computer using. In the case about the assembly language was been defined by Intel (x86).The ".code" indicates that the hexadecimal is executable and not data. Example of executable code would be "MOV EBP,ESP". This assembly language means move ESP into EBP. The CPU would interrupt this assembly language as a doable action. The ".data" indicates that the hexadecimal is data. An example of data would be the phrase "I Love You.".
C Programming Language
#include
main()
{
printf("I Love You");
}
Assembly Language is considered a low level programming language. This is due to it's close interaction with the CPU. Interaction at this level is extremely complicated. To ease the complexity higher level programming languages were created. An example of this can be seen in the code above written in the C programming language. Three lines of code in C is equal to 17 lines of assembly.
In order to get from C to the binary digits the code would need to be compiled. A compiler converts source code to a binary format. The final output that the user would see if they clicked on the compiled C code.
I Love You.
To recap the computer at it's lowest level stores everything as ones and zeros, the source code is compiled to create the binary, those ones and zeros can be read as hexadecimal, the hexadecimal can then be converted to either assembly language or data.
I liked your article - very informative. I'd like to make a quick correction, though. It says in the article: "Hexadecimal is a base-16 numeral format. Rather than having two states as in the case of binary hexadecimal can have 16 states. The different states are represented by the digits 1,2,3,4...9,A,B,C,D,E,F. The digit 'E' equals 15 in decimal." Actually though, hex is represented by the digits 0-9 and A-F (you accidentally left out zero), which means the digit 'E' actually equals 14, not 15.
ReplyDeleteThanks. I'm surprised I missed that. I really need to proofread some of these old articles.
Delete