Languages of Computers
Understanding Binary
The binary system, also known as the base-2 numeral system, uses only two symbols: 0 and 1.
It forms the foundation of digital computing, as it corresponds directly to the two states of a digital circuit: on [1] and off [0].
The binary system is used to represent data, perform calculations, and control logic operations in computers.
In the binary system, each digit's position corresponds to a power of 2, with the rightmost digit representing 2^0 [1],
the next digit to the left representing 2^1 [2], and so on.
To convert a binary number to its decimal equivalent, we simply add the products of each binary digit and its corresponding power of 2.
For example, the binary number 1101 can be converted to decimal as follows:
[1 × 2^3] + [1 × 2^2] + [0 × 2^1] + [1 × 2^0] = 8 + 4 + 0 + 1 = 13.
Another example: Let's take the binary number 1101 and convert it to decimal.
To do this, we will multiply each digit by the power of 2 corresponding to its position, starting from the rightmost digit [the least significant bit].
Here's the process: [1 * 2^3] + [1 * 2^2] + [0 * 2^1] + [1 * 2^0] = [1 * 8] + [1 * 4] + [0 * 2] + [1 * 1] = 8 + 4 + 0 + 1 = 13 So,
the binary number 1101 is equal to the decimal number 13. Example 2: Take the binary number 101010 and convert it to decimal.
To do this, we will multiply each digit by the power of 2 corresponding to its position, starting from the rightmost digit [the least significant bit].
Here's the process:
[1 * 2^5] + [0 * 2^4] + [1 * 2^3] + [0 * 2^2] + [1 * 2^1] + [0 * 2^0] = [1 * 32] + [0 * 16] + [1 * 8] + [0 * 4] + [1 * 2] + [0 * 1] = 32 + 0 + 8 + 0 + 2 + 0 = 42 So,
the binary number 101010 is equal to the decimal number 42.
Digital Sizes
Digital size units are used to represent the amount of data or storage capacity in computers and digital devices.
The most basic unit is the bit, which can have a binary value of 0 or 1.
Nibbles, bytes, kilobytes, megabytes, gigabytes, and terabytes are progressively larger units used to represent larger amounts of data.
While the base-10 system is commonly used in the computer storage industry, the base-2 system is also used,
especially in computer memory and programming contexts.
Unint |
Size [In Bits] |
Bit |
1 |
Nibble |
4 |
Byte |
8 |
Kilobyte [KB] |
8,192 bits or 1,024 bytes |
Megabyte [MB] |
8,388,608 bits or 1,048,576 bytes |
Gigabyte [GB] |
8,589,934,592 bits or 1,073,741,824 bytes |
Terabyte [TB] |
8,796,093,022,208 bits or 1,099,511,627,776 bytes |
Bit - A bit is the smallest unit of digital information and represents a single binary digit, which can be either 0 or 1.
Nibble: A nibble is a group of four bits, which can represent a single hexadecimal digit [0-9 and A-F].
Byte - A byte is a group of eight bits, which is the basic unit of digital storage in most computer systems.
A byte can represent a single ASCII character or a small number.
Kilobyte [KB] - A kilobyte is equal to 1,024 bytes or 8,192 bits.
It is commonly used to represent small files, such as text documents or images with low resolution.
Megabyte [MB] - A megabyte is equal to 1,048,576 bytes or 8,388,608 bits.
It is commonly used to represent larger files, such as music or high-resolution images.
Gigabyte [GB] - A gigabyte is equal to 1,073,741,824 bytes or 8,589,934,592 bits.
It is commonly used to represent even larger files, such as videos or software applications.
Terabyte [TB] - A terabyte is equal to 1,099,511,627,776 bytes or 8,796,093,022,208 bits.
It is commonly used to represent very large amounts of data, such as in data centers or cloud storage.
Introduction to ASCII
The American Standard Code for Information Interchange [ASCII] is a character encoding standard that represents text in computers, communication equipment, and other devices that use text.
It was first developed in the 1960s as a standardized way to represent characters on electronic devices,
including letters, numbers, punctuation marks, and some control characters.
ASCII is a 7-bit character encoding, which means it can represent 2^7 or 128 different characters.
The characters are assigned numeric values, ranging from 0 to 127.
These values are used to represent the characters in binary form, with each value represented by a unique 7-bit binary number.
Hexadecimal [Base 16]
Hexadecimal, or simply hex, is a number system that represents numbers using a base-16 notation.
Unlike the familiar decimal system [base-10], which uses digits 0 through 9, the hexadecimal system uses sixteen distinct symbols:
0-9 to represent the values 0 to 9, and A-F to represent values 10 to 15.
Hexadecimal notation is widely used in computing and programming due to its concise representation
of binary data and ease of conversion between binary and hexadecimal.
A single hexadecimal digit can represent four binary digits, or bits, making it a compact way to display binary values.
For example, the binary value 1101 can be represented as D in hexadecimal.
To convert between hexadecimal and decimal or binary, follow these steps:
Hexadecimal to Decimal - Multiply each hexadecimal digit by the corresponding power of 16.
Sum the resulting values.
Example: Convert 2A3 to decimal:
2 * [16^2] + 10 * [16^1] + 3 * [16^0] = 512 + 160 + 3 = 675
Decimal to Hexadecimal - Divide the decimal number by 16.
Write down the remainder.
Repeat the process with the quotient until the quotient is 0.
The hexadecimal representation is the sequence of remainders in reverse order.
Example: Convert 675 to hexadecimal:
675 / 16 = 42, remainder 3 [3]
42 / 16 = 2, remainder 10 [A]
2 / 16 = 0, remainder 2 [2]
The hexadecimal representation is 2A3.
Hexadecimal Encoding and Decoding Examples:
Hexadecimal encoding is often used to represent binary data, such as RGB color codes, memory addresses, or checksums.
RGB Color Codes: #FF0000 represents red, where FF is red, 00 is green, and 00 is blue.
Memory Addresses: 0x7FFDE000 is a hexadecimal representation of a memory address.
Checksums: 2A3B5C is an example of a hexadecimal checksum value.
Base64 Encoding and Decoding
Base64 is a binary-to-text encoding scheme that represents binary data in an ASCII format.
It is commonly used for transmitting binary data over protocols that only support ASCII characters, such as email and HTTP.
Base64 converts binary data into a series of 64 printable characters, which can be transmitted over any text-based protocol.
To understand Base64, imagine you want to send a photo to a friend via email. The photo is a binary file, which means it is made up of 1s and 0s.
However, email can only transmit text-based data, such as letters and symbols, this is where Base64 comes in.
You can convert the binary photo into a Base64- encoded string of text, which can then be sent over email.
Here's a simple example to illustrate how Base64 works.
Let's say we want to encode the binary sequence 11010111 01101000 00110001 00110011 into Base64.
To do this, we first split the binary sequence into groups of six bits, like this:
110101 110110 001100 110011
Then, we convert each group of six bits into its corresponding Base64 symbol. The Base64 symbols are:
ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/
So, the first group of six bits [110101] corresponds to the Base64 symbol "1",
the second group [110110] corresponds to the Base64 symbol "2", and so on.
After converting all four groups of six bits, we get the Base64-encoded string "1mww".
To decode a Base64-encoded string back into its original binary format, the process is reversed.
Each Base64 symbol is converted back into its corresponding six bits,
and the resulting binary sequence is combined to recreate the original binary data.
Cryptographic Hash Functions Exploring MD4, MD5, & SHA Algorithms
Cryptographic hash functions are mathematical algorithms that take an input and produce a fixed-size output, typically called a hash or digest.
Hash functions are designed to be deterministic, meaning the same input will always produce the same output.
They are also designed to be one-way functions, meaning it should be computationally infeasible to reverse-engineer the input from the output.
Common hash functions include MD4, MD5, and the SHA family of algorithms.
MD4 & MD5 - MD4 [Message Digest Algorithm 4] and MD5 [Message Digest Algorithm 5] are two hash functions created by
Ronald Rivest in the early 1990s.
MD4 is a 128-bit hash function, while MD5 produces a 128-bit output as well.
Though they were widely used in the past,
both MD4 and MD5 are now considered insecure due to their susceptibility to various types of attacks,
including collision attacks and preimage attacks.
Example: MD5 hash of the string "hello": 5d41402abc4b2a76b9719d911017c592
SHA [Secure Hash Algorithm] Family - The SHA family of algorithms was developed by the National Security Agency [NSA]
and includes multiple variations, such as SHA-0, SHA-1, SHA-2, and SHA-3.
Among these, SHA-1 and SHA-2 are the most widely used. SHA-1 produces a 160-bit hash,
while SHA-2 has several versions [SHA-224, SHA256, SHA-384, SHA-512] with different output sizes.
Due to security concerns, SHA-1 is no longer considered secure, and the use of SHA-2 or SHA-3 is recommended.
Example: SHA-256 hash of the string "hello": 2cf24dba5fb0a30e26e83b2ac5b9e29e1b161e5c1fa7425e73043362938b9824
Practical Uses of Hash Functions:
File Integrity Verification - By comparing the hash of a downloaded file to the original hash provided by the author,
users can verify that the file has not been tampered with or corrupted.
Password Storage - Storing hashes of user passwords instead of plain text helps protect sensitive information in case of a data breach.
Digital Signatures - Hash functions are used in digital signatures to ensure the integrity and authenticity of messages or documents.
Blockchain Technology - Cryptographic hash functions play a crucial role in securing blockchain networks,
such as Bitcoin, by verifying and linking blocks of transactions.
The Differences Between Encoding Hashing Encryption
Encoding - Encoding is the process of converting data from one format to another format.
It's often used to make data more suitable for transmission or storage. For example, when sending an email,
special characters or non-ASCII characters may be encoded in order to ensure that the recipient can properly read the email.
Encoding does not provide any security, as the encoded data can be easily decoded by anyone who knows the encoding method used.
Hashing - Hashing is a technique used to ensure data integrity, meaning that the data has not been modified or tampered with.
Hashing takes a piece of data and generates a fixed-length string of characters,
called a hash value or message digest,which is unique to that data.
If the data is modified, the hash value will change.
Hashing is a one-way process, meaning that it's impossible to generate the original data from the hash value.
Hashing is often used to store passwords securely, as the password is hashed and stored instead of the plaintext password itself.
Encryption - Encryption is the process of converting plaintext (unencrypted) data into ciphertext (encrypted) data,
so that it can only be read by someone who has the decryption key.
Encryption is often used to protect sensitive information, such as credit card numbers,
personal information, or confidential business data.
Encryption can be either symmetric, where the same key is used to encrypt and decrypt the data,
or asymmetric, where two different keys are used.
Asymmetric encryption is typically more secure than symmetric encryption, but it's also slower and more resource-intensive
▲
▼