# Tag Info

46

This seems a very basic question to me, so excuse me if I lecture you a bit. The most important point for you to learn here is that a number is not its digit representation. A number is an abstract mathematical object, whereas its digit representation is a concrete thing, namely a sequence of symbols on a paper (or a sequence of bits in compute memory, or a ...

30

While you will need fewer 80-based numbers than 2-based numbers (bits) to encode the same file, the only way to store these 80-based numbers on a computer is to encode them as bits. So you do not gain anything. In fact you actually lose space, since 80 is not a power of 2: You will need 7 bits for each 80-based number, but in these 7 bits you could instead ...

22

There is no way to represent all real numbers without errors if each number is to have a finite representation. There are uncountably many real numbers but only countably many finite strings of 1's and 0's that you could use to represent them with.

20

It all depends what you want to do. For example, what you show is a great way of representing rational numbers. But it still can't represent something like $\pi$ or $e$ perfectly. In fact, many languages such as Haskell and Scheme have built in support for rational numbers, storing them in the form $\frac{a}{b}$ where $a,b$ are integers. The main reason ...

10

There are several ways to interpret the question. What I think you might be asking is that you have a sequence of $n$ letters in an alphabet $\Sigma$ where $\left| \Sigma \right| = 80$. You want to store this in as few as possible bits. We will assume that the letters in the alphabet are uniformly distributed. The information-theoretic amount of space ...

9

This is just a refactoring (Python 3) of Andrej's code. In Andrej's code numbers are represented through a list of digits (scalars), while in the following code numbers are represented through a list of symbols taken from a custom string: def v2r(n, base): # value to representation """Convert a positive number to its digit representation in a custom ...

7

Two's complement makes sense when the two entities in question have the same "units" and the same "width". By width I mean that, say, if you're adding an N bit number and an M bit number, where N and M are different, then you better not use two's complement. For floating point numbers, we have the problem of units: if the exponents are different, then we are ...

7

Your idea does not work because a number represented in base $b$ with mantissa $m$ and exponent $e$ is the rational number $b \cdot m^{-e}$, thus your representation works precisely for rational numbers and no others. You cannot represent $\sqrt{2}$ for instance. There is a whole branch of computable mathematics which deals with exact real arithmetic. Many ...

7

There are many effective Rational Number implementations but one that has been proposed many times and can even handle some irrationals quite well is Continued Fractions. Quote from Continued Fractions by Darren C. Collins: Theorem 5-1. - The continued fraction expression of a real number is finite if and only if the real number is rational. Quote ...

7

This is best explained in the base 10 equivalent: scientific notation In scientific notation you have a mantissa and a exponent such that the value is $\mathrm{mantissa} \cdot 10^{\mathrm{exponent}}$. In a computer floating point the mantissa is always the same size of significant digits (a double precision has around 16 digits) and the exponent is bounded....

6

In a floating point, by definition, the point floats. What you're proposing is fixed point (which is occasionally used in practice). A normal IEEE 754 64-bit double precision can store values in the range from $-10^{308}$ to $10^{308}$. This is a much larger range than your system can store given 64 bits (you would need nearly 800 bits to achieve the same). ...

5

There are a number of "exact real" suggestions in the comments (e.g. continued fractions, linear fractional transformations, etc). The typical catch is that while you can compute answers to a formula, equality is often undecidable. However, if you're just interested in algebraic numbers, then you're in luck: The theory of real closed fields is complete, o-...

5

If you drop the leading zeroes then $3,5,9,17$ and so on will all have the same representation. Don't forget that the number being represented need not be an integer.

5

Generally speaking, normalized means "put in scientific notation." That just means, the mantissa should never start with 0, and should be less than the base. In binary that means the mantissa must be "1". Since the mantissa of a normalized binary floating point number is always 1, we don't need to store the 1. The first mantissa bit is hidden in the ...

5

Just converting the comment into a short answer: $7 = \text{int}(\log_{2} 236)$. Generally, $p = \text{int}(\log_{B}V)$. As other people pointed out, this algorithm is needlessly complicated and not practical; it is not easy to calculate $\log_B V$ for large $V$ by pencil and paper. Instead, use the other algorithm which is also mentioned in the article ...

4

But why is a sign bit necessary for floating point numbers False assumption. It isn't necessary. I'm pretty sure I've met floating point formats which used 2's complement for the mantissa, but I'd have to dig out for names. I'm far from being a specialist in numerical analysis, but I get that having signed zero is important for them. It's probably easier ...

4

From Wikipedia: The two's-complement system has the advantage that the fundamental arithmetic operations of addition, subtraction, and multiplication are identical to those for unsigned binary numbers... Two's-complement is a representation of negative numbers that just so happens to be very convenient. That's the whole reason to use it at all. A ...

4

I don't know what calculators actually use, but there are definitely better algorithms than your brute force search. There are several notions of “best approximation” of a real number by a rational. Depending on how you rate the benefit of a good approximation compared to the cost of a large denominator, you get different notions. One of these is the best ...

4

Continued fractions are an efficient way to enumerate rational numbers that are a good approximation of your number $x$. In particular, given a real number $x$, you can generate a sequence of truncated continued fractions $a_i/b_i$, where each rational number $a_i/b_i$ is a better approximation to $x$ than any other fraction whose denominator is $\le b_i$. ...

4

Yes, there is a usage for the negative imaginary zero. But first, I will say something about the negative zero in general. Why have a negative zero? First of all, the main reason to have a signed zero for floating points is that floating points have only limited precision and we often want to distinguish the following cases of a real number $x$, ...

3

If you have a number (eg. 123456789⏨) as text you can write it in a different base (such as 21i3v9 in base 36), so you compress it written as text (from 9 characters to 6). If you go further you end up storing it in binary (4 bytes¹). Now, this works because you started with a reduced set [0-9] and moved to a bigger one [0-9a-z] and many bits of data were ...

3

The reason we get a larger range is denormalized numbers. Generally speaking, floating point numbers have three physical parts: sign (1 bit), mantissa $M$ and exponent $e$. Most of the time we think of the number as $\operatorname{sgn} \times 1.M \times 2^{e-e_0}$, where $e_0 = 2^{|e|}-1$ (e.g. for single precision, it's 127, since the exponent is allotted ...

3

The second exponent is FF, which signals NaN according to Wikipedia, and so the highest exponent is only FE. This is verified by the following C code snippet: unsigned int i = 0x7FFFFFFF; float f = *(float*)&i; If you print f you get nan.

3

The fractional part is in binary: $(0.01010101\ldots)_2 = (0.333333\ldots)_{10}$. To convince yourself of this, try multiplying the binary $0.0101010101\ldots$ by $3$: you will get $0.111111\ldots = 1$. In a similar way, the decimal $0.0101010101\ldots$ equals $1/99$. The mantissa (fractional part) in fact has an implicit $1.$ in front, so it actually ...

3

A brute force solution is to trace the line ay=bx in integer coordinates from the origin to (a,b). Any pair with a smaller number of bits will be along that line segment. This method allows finding either the minimum distance or the smallest (x,y) within the error bounds. It requires o(a+b) steps, and there's plenty of redundancy possible, since eg both (x,...

3

I'm assuming you're talking about IEEE754. Unless I'm missing something, your book is wrong. Every number in IEEE754 is represented as normalized (starting with a 1), unless your number is subnormal. A number is only subnormal if the mantissa is minimal (all zeroes). Since the first bit is the sign bit, $10$ could be the start of a subnormal number. For ...

3

In answer to the OP, and looking around Tony Piper I found this page: http://www.teach-ict.com/as_as_computing/ocr/H447/F453/3_3_4/floating_point/miniweb/pg10.htm Essentially, a non-normalised 8 bit floating point is represented like: Sign Integer Fraction Exponent 0 111 .0 010 The largest number this can represent is 111.1 with a 111 ...

3

Historically, floating point binary formats have varied from machine to machine. For example, some put the exponent on the left and the mantissa on the right, and some use sign and magnitude instead of twos complement. It wasn’t until 1985 that the Institute of Electrical and Electronics Engineers agreed on the standard format used in most of today’s ...

3

A good start is to expand the hex representation into binary like how you did it. 0000 1100 0000 0000 0000 0000 0000 0000 Then parse the word: the left-most bit is the sign bit the next 8 bits represent the biased-exponent the last bits represent the fractional part with the "hidden one" 0 | 00011000 | 00000000000000000000000 Then, follow: s ...

Only top voted, non community-wiki answers of a minimum length are eligible