Questions tagged [bit-representation]
43 questions
16
votes
2 answers
How To Represent 0.1 In Floating Point Arithmetic And Decimal
I am trying to understand floating point arithmetic better and have seen a few links to 'What Every Computer Scientist Should Know About Floating Point Arithmetic'.
I still don't understand how a number like 0.1 or 0.5 is stored in floats and as…

Jack Kada
- 24,474
- 29
- 82
- 106
11
votes
3 answers
Are there any existing C implementations having padding bit in (un)signed integer representation?
As per C99, there maybe padding bits in signed int or unsigned int representation . So I wonder are there still any implementations having such outdated things?

l4rmbr
- 1,227
- 7
- 22
9
votes
3 answers
C++ Portable Floating-Point Bit Representation?
Is there a C++ Standards compliant way to determining the structure of a 'float', 'double', and 'long double' at compile-time ( or run-time, as an alternative )?
If I assume std::numeric_limits< T >::is_iec559 == true and std::numeric_limits< T…

Charles L Wilcox
- 1,126
- 8
- 18
8
votes
2 answers
Can pointers to different types have different binary representations?
I wonder if C++ implementations are allowed to represent pointers to different types differently. For instance, if we had 4-byte sized/aligned int and 8-byte sized/aligned long, would it be possible to represent pointers-to-int/long as object…

Daniel Langr
- 22,196
- 3
- 50
- 93
7
votes
2 answers
Rounding floats with representation error to the closest and correct result
I have a situation when the classic representation error in Python started to be a problem: I need them to be used for Matrix operations in Numpy and the decimal type is not supported yet.
You all know that if I do 111.85 * 111.85 I will get…

gerosalesc
- 2,983
- 3
- 27
- 46
6
votes
1 answer
How to check whether an int variable contains a legal (not trap representation) value?
Context:
This is mainly a followup to that other question. OP wanted to guess whether a variable contained an int or not, and my first thought was that in C (as in C++) an int variable could only contain an int value. And Eric Postpischil reminded…

Serge Ballesta
- 143,923
- 11
- 122
- 252
5
votes
4 answers
Can a type in C have more than one object representation?
The C99 standard, section 6.2.6.1 8, states:
When an operator is applied to a value that has more than one object
representation, which object representation is used shall not affect
the value of the result (43). Where a value is stored in an…

cmutex
- 1,478
- 11
- 24
4
votes
1 answer
In Python, how can I translate *(1+(int*)&x)?
This question is a follow-up of this one. In Sun's math library (in C), the expression
*(1+(int*)&x)
is used to retrieve the high word of the floating point number x. Here, the OS is assumed 64-bit, with little-endian representation.
I am…

zell
- 9,830
- 10
- 62
- 115
4
votes
2 answers
Value of 1024 has one bit more in binary representation that value of 1
The output of following code:
System.out.println( Long.toBinaryString( Double.doubleToRawLongBits( 1 ) ) );
System.out.println( Long.toBinaryString( Double.doubleToRawLongBits( 1024 ) )…

Piotr Müller
- 5,323
- 5
- 55
- 82
3
votes
4 answers
Is the double 0.0 always represented exactly in portable C?
Can the following code be expected to work in all environments that have an ANSI-compliant C compiler?
double n = 0;
assert(n == 0);
What about C++?

kirakun
- 2,770
- 1
- 25
- 41
3
votes
1 answer
applying sign to dicom image for 16 bit
I am trying to develop a dicom image viewer. I have successfully decoded the image buffer. I store all the image pixel values in an unsigned char buffer in C++.
Now, when I display the image it is working fine for images with pixel representation…

user6848035
- 81
- 6
3
votes
5 answers
Question about relations between two numbers
Is there is any relation between numbers' bits when one is divisible by another? What is the relation between the bits of 36 and the bit sequences of 9 or 4 or 12, or between 10 (1010) and 5 (101), or 21 (10101) and 7 (00111)?
Thanks. I am sorry…
user466534
3
votes
6 answers
Is there any way to reverse the order of bits in matlab
What I am trying is getting binary value of a number e.g
de2bi(234)
Which results me in having this answer :
0 1 0 1 0 1 1 1
now what I want is that is its reverse order without changing its values like this…

Aqeel Abbas
- 159
- 4
- 13
2
votes
3 answers
Unspecified behaviour about "object having more than one object representation"
Still struggling with C (C99) undefined and unspecified behaviours.
This time it is the following Unspecified Behaviour (Annex J.1):
The representation used when storing a value in an object that has
more than one object representation for that…

Guillaume Petitjean
- 2,408
- 1
- 21
- 47
2
votes
0 answers
How to check In C language whether an int variable contains a legal (not trap representation) value?
Context:
This is a followup to that other question of mine. I asked about both C and C++ and soon got an answer about C++ because last draft for C++20 explicitly requires that signed integer types use two's complement and that padding bits (if any)…

Serge Ballesta
- 143,923
- 11
- 122
- 252