Skip to main content
Share Your Experience: Take the 2024 Developer Survey
32 votes
Accepted

Why is 2s complement of 000 equal to 111, but 9s complement of 000 is not 888?

You are very confused due what is simply poor terminology, to be honest. Both your statements 2 and 3 are false due to the same misunderstanding. For each base $b$ there are two mainstream variants of ...
orlp's user avatar
  • 13.6k
12 votes

The math behind converting from any base to any base without going through base 10?

This is a refactoring (Python 3) of Andrej's code. While in Andrej's code numbers are represented through a list of digits (scalars), in the following code numbers are represented through a list of ...
mmj's user avatar
  • 221
12 votes

Why is 2s complement of 000 equal to 111, but 9s complement of 000 is not 888?

The two's complement of 000 is 000. It is formed by complementing all bits and adding 1 to the result. The one's complement of 000 is indeed 111, but it is not used in computing. The ten's complement ...
Yuval Filmus's user avatar
6 votes

Why aren't numbers stored this way?

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 ...
Tom van der Zanden's user avatar
6 votes
Accepted

Imaginary numbers and negative zero

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 ...
Discrete lizard's user avatar
  • 8,248
6 votes
Accepted

Why does little endian apply to numbers and not to text strings?

The premise is wrong. Unicode encodings include UTF-16BE, UTF-16LE, UTF-32BE and UTF32-LE. Only UTF-8 has no Litte-Endian or Big-Endian variants. Fundamentally, Endian-ness is about the byte order of ...
MSalters's user avatar
  • 895
5 votes

Is there any practical trick to mentally count in Gray code?

I have a solution that I just found looking at the patterns, and I checked the pattern up to decimal 31 or binary 11111 or Gray 10000, and it worked quite fine, and I am confident enough the answer ...
Krischal Khanal's user avatar
5 votes

The math behind converting from any base to any base without going through base 10?

Fundamental operation of base convertion is the toDigits() operation of @AndrejBauer answer. However, to make it there is no need to create a number in the internal ...
Xavier Combelle's user avatar
5 votes

Is decimal number 8 represented as 3 bits or 4 bits in computer?

$b$ bits have a total of $2^b$ distinct bit-patterns. To store 8 distinct values, you need at least 3 bits. This does not tell you on its own how many bits are required to store the number 8, because ...
Curtis F's user avatar
  • 1,043
4 votes
Accepted

Smallest number close to 0 in IEEE754 (64bits)?

It's not true that when all components of the exponent are 0 then the number must represent 0. A (normalized) floating point number is composed of two parts: sign, exponent, and mantissa. The value of ...
Yuval Filmus's user avatar
3 votes

Why aren't numbers stored this way?

The gravitational constant is about $6.67 \times 10^{-11} N m^2 kg^{-2}$. You would want a scheme that allows storing this number at the full known precision. Unfortunately, it is about 1 quarter of ...
gnasher729's user avatar
  • 30.4k
3 votes
Accepted

Convert integer of mixed radix to standard positional numeral system and vice versa

If you have numbers $x_1,\ldots,x_n$ in the ranges $x_1 \in \{0,\ldots,b_1-1\},\ldots,x_n \in \{0,\ldots,b_n-1\}$, you can get a number in the range $\{0,\ldots,b_1\ldots b_n-1\}$ using the formula $$ ...
Yuval Filmus's user avatar
3 votes

Why do floating point additions sometimes produce equal results?

Floating point numbers have limited accuracy. They are stored in the following way: $\pm 1.x_0\ldots x_{n-1} \times 2^y$ (here $x_0,\ldots,x_{n-1}$ are binary digits) for an appropriate $n$; the value ...
Yuval Filmus's user avatar
3 votes

Floating point normalised numbers in binary

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 ...
Drummy's user avatar
  • 131
3 votes

Why floating point representation uses a sign bit instead of 2's complement to indicate negative numbers

IEEE 754 uses sign/magnitude, not two's complement or one's complement. Two's complement has the disadvantage that the positive and negative range are not identical. If all bit patterns are valid, ...
gnasher729's user avatar
  • 30.4k
3 votes

Why can we write almost any nonzero 2-adic integer in the same form?

The pattern $x = (\alpha01^a10^b)_2$ is very easy to match. For example, the number $1=0^\infty1$ matches the pattern with $\alpha=0^\infty, a=b=0$. Try matching some other numbers yourself. The only ...
Karolis Juodelė's user avatar
3 votes
Accepted

Repeated addition and comparisons of floating point numbers

The reason you are seeing these results are not due to the memory limits of your computer, but rather of the limits of the encoding of "floating point" numbers. Python uses 64 bit floats (aka double ...
Jack's user avatar
  • 113
3 votes

facts about ieee 754

"Floating point" means a representation in which the position of the fraction indicator (the "point") in a number is allowed to take on a range of values, allowing the fixed-length representation of ...
rici's user avatar
  • 12k
2 votes

Why floating point representation uses a sign bit instead of 2's complement to indicate negative numbers

Having signed zeros gives increased expressiveness that may be useful in numerical computations. The wikipedia page ‘Signed zero’ says: It is claimed that the inclusion of signed zero in IEEE 754 ...
equaeghe's user avatar
  • 190
2 votes

Convert 24(decimal) to modified IEEE 754 floating point format?

Since $e=111$ is saved for indicating NaN and $\infty$, then the maximal number that can be represented with this 8bit-floating point structure is $$ (-1)^0 \cdot (1.1111)_b \cdot 2^{6-3} = 15.5$$ ...
Ran G.'s user avatar
  • 20.7k
2 votes

What does normalizing with hidden bit really mean?

Shorter Answer (As requested by greybird in the comments) : The gist of "normalizing" in scientific notation, is not to allow the same number to have ...
aderchox's user avatar
  • 121
2 votes

What happens if we add denormalized number and normalized number?

The result depends on the difference between the normal and denormal numbers you are adding. $1 + [denormal]$ is rounded to $1$. But if the range difference between your numbers is inferior to $2^{...
Grabul's user avatar
  • 1,870
2 votes

How to work out if an IEEE 754 floating point number is normalized?

For single-precision floating-point numbers you need to check if the following condition holds for the exponent $e$: $0 < e < 255$. The exponent occupies bits $30 .. 23$ (including both ends) of ...
Anton Trunov's user avatar
  • 3,479
2 votes

Difference between ways to compare floating-point numbers

You are rightfully confused, because these answers mix up incompatible concepts into a right mess. If you want to know whether two floating point numbers are equal then you use the "==" operator, ...
gnasher729's user avatar
  • 30.4k
2 votes

Why do we need to convert binary numbers into hexadecimal, octal and decimal?

You got it in one. Hex is easier for humans to read but also trivial to convert to and from binary. The computer itself only uses binary, in the sense that every wire is either on or off. But, at the ...
David Richerby's user avatar
2 votes

Is there any practical trick to mentally count in Gray code?

The title of my masters thesis was Efficient Hardware Implementations of Gray Code Arithmetic. The goal was to find a way to, at the digital hardware level, perform arithmetic on Gray code directly ...
Gil Glass's user avatar
2 votes
Accepted

Confusion in 2's complement of 00000000

You have 00000000 as the number, it implies how many bits are used. The 1 at the front comes from carry bit, but two complements does not extend number of bits used, so the answer is 00000000, as the ...
Evil's user avatar
  • 9,465
2 votes
Accepted

Why can we write almost any nonzero 2-adic integer in the same form?

Addressing first the explicitly asked questions: Two things bug me about this: 1. "is almost any" is imprecise, The meaning of “almost any” here is given in the next sentence, in the same ...
ShreevatsaR's user avatar
2 votes

Overflow rule in two's complement arithmetic

Yes, if we are talking about integers. In two's complement representation with length $n$ you can only represent the integers between $-2^{n-1}$ and $2^{n-1} - 1$ (both bounds inclusive). Thus, the ...
dkaeae's user avatar
  • 5,027

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