Today I Learned

6

Days Learned

Why does x86 mean 32-bit?

COPY LINK

Well it finally happened… I accidently dowloaded an x86 binary thinking it was 64-bit.

Why on God’s green earth is x86 32-bit?

x64 is well rightfully named 64-bit, then what the hell is amd64? I have a 64-bit Intel machine so should I download the x64 version or amd64? If amd64 exists then what about intel64? And if x86 is 32-bit then why does x32 exist?

Well now I know!

x86 basically refers to the family of Intel processor architecture that was used in PC’s such as the 8086, 8088, 286 etc,. So the entire architecture family became know as x86, when 32-bit became dominant x86 became synonymous with 32-bit.

x64 is the architecture name for the extension of the x86 instruction set to 64-bit. It was invented by AMD. At the same time Intel was working on their 64-bit architecture called Itanium which flopped badly, so they copied AMD’s x64, and called their version Intel 64. AMD called the x64 architecture x86_64 or amd64 and these name were commonly used in open source tools. The name Intel 64 or EM64T never caught on.

So whenver you have to download any binary for your modern 64-bit computer, if you see a binary for amd64 it will run on your intel machine. It is the same architecture but has multiple names for it , amd64 (mosly used by the open source and linux community), x86_64 the original official name by AMD, x64 (used in Windows) and Intel 64 which is a dead name used nowhere except inside Intel manuals.

x32 is not associated with hardware, it is an ILP32 variant of the x86-64 System V ABI: 32-bit pointers in 64-bit mode according to the x32 ABI spec. You should not see any binaries or packages named for x32, as it is NOT an instruction set.


Why is most audio sampled at 44.1KHz?

COPY LINK

It is know that human hearing tops at 20Khz. The Nyquist sampling theorem states that a digital system can perfectly reproduce any frequency up to half its sample rate.

Therefore to capture every frequency a human can hear we need Nyquist frequency of 40Khz.

Then why 44.1KHz?

In the early days of digital audio, storing the equivalent of a CD album worth of digital data on a hard drive was not possible because the drives of the time simply did not have sufficient capacity. Therefore the video recorders were repurposed to store audio samples as black and white video signals. These video recorders ran at 30 frames per second and had 490 useable lines per frame. It was decided that 3 audio samples should be stored per line of video.

3 samples/line * 490 lines/frame * 30 frames/sec = 44100 samples/sec


Polling is discrete

COPY LINK

Polling is an I/O technique in which the CPU repeatedly checks the status of a peripheral device. In the case of keyboard polling, the computer polls the keyboard at fixed intervals, and the keyboard responds with which keys are pressed. For a slower polling frequency, if a key is pressed between two polls, the computer will miss that key. The higher the polling frequency, the fewer key misses.


Computers multiply big numbers fast by reducing multiplication

COPY LINK

The Karatsuba algorithm reduces the number of multiplications needed for two n-digit numbers that require k multiplication steps by substituting them with k-1 multiplications plus an addition instead of k multiplications, as multiplication is asymptotically more expensive than addition.


.bss section stores unintialized varibales

COPY LINK

The .data section in ELF binaries is used for holding initialized global or static variables. The local variables are stored in the stack. All the uninitialized global or static variables are stored in the .bss section and occupy no space in the binary, as they are zeroed at runtime.


Base64 encoding

COPY LINK

Base64 encoding allows us to encode any bytes to “safe” bytes, bytes which are known to be safe to send without getting corrupted.

Example of “unsafe” bytes would be control characters.

To send text with Base64 encoding we first encode the text to say UTF-8, after that we group the binary into chunks of 3 bytes, we further divide the chunks into four 6-bit groups. Now each 6-bit group can represent values between 0 and 63, these values are then mapped to the corresponding Base64 character.

What if the chunks are not of 3 bytes?

For 1 extra byte we have space left for 2 bytes, we pad the econding with ==

For 2 extra byte we have space left for 1 byte, we pad the encoding with =

The reciever will have to reverse the process to recover the original text.