Is floating point precision mutable or invariant?

The precision is fixed, which is exactly 53 binary digits for double-precision (or 52 if we exclude the implicit leading 1). This comes out to about 15 decimal digits. The OP asked me to elaborate on why having exactly 53 binary digits means “about” 15 decimal digits. To understand this intuitively, let’s consider a less-precise … Read more

Why does a byte only have 0 to 255?

Strictly speaking, the term “byte” can actually refer to a unit with other than 256 values. It’s just that that’s the almost universal size. From Wikipedia: Historically, a byte was the number of bits used to encode a single character of text in a computer and it is for this reason the basic addressable element … Read more

What are important points when designing a (binary) file format? [closed]

Take a look at the PNG spec. This format has some very good rationale behind it. Also, decide what’s important for your future format: compactness, compatibility, allowing to embed other formats (different compression algorithms) inside it. Another interesting example would be the Google’s protocol buffers, where size of the transferred data is the king. As … Read more

Is it possible to program in binary?

Of course. It’s more commonly called machine code. It’s basically assembly language without the mnemonic devices. Someone who knows assembly very well could program in machine code with additional effort, referring to opcode listings (e.g. x86) as needed. Would I do it? No. Even assembly is only useful in rare circumstances, and there’s no reason … Read more

How do you convert a fraction to binary?

In university I learned it this way: Multiply by two take decimal as the digit take the fraction as the starting point for the next step repeat until you either get to 0 or a periodic number read the number starting from the top – the first result is the first digit after the comma … Read more

Advantage of 2’s complement over 1’s complement?

The primary advantage of two’s complement over one’s complement is that two’s complement only has one value for zero. One’s complement has a “positive” zero and a “negative” zero. Next, to add numbers using one’s complement you have to first do binary addition, then add in an end-around carry value. Two’s complement has only one … Read more