Questions tagged [data-representation]
177 questions
504
votes
24 answers
What is “two's complement”?
I'm in a computer systems course and have been struggling, in part, with two's complement. I want to understand it, but everything I've read hasn't brought the picture together for me. I've read the Wikipedia article and various other articles,…

Frank V
- 25,141
- 34
- 106
- 144
20
votes
2 answers
R largest/smallest representable numbers
I'm trying to get the largest/smallest representable number in R.
After typing ".Machine"
I got:
$double.xmin
[1] 2.225074e-308
$double.xmax
[1] 1.797693e+308
However even if I type 2.225074e-309 in R command prompt I get 2.225074e-309 instead of…

Imlerith
- 479
- 1
- 7
- 15
20
votes
4 answers
Why is varint an efficient data representation?
I am currently studying the documentation of protocol buffers. Varints are described as:
Each byte in a varint, except the last byte, has the most significant
bit (msb) set – this indicates that there are further bytes to come.
The lower 7 bits…
user878242
20
votes
8 answers
What do the C and C++ standards say about bit-level integer representation and manipulation?
I know the C and C++ standards don't dictate a particular representation for numbers (could be two's complement, sign-and-magnitude, etc.). But I don't know the standards well enough (and couldn't find if it's stated) to know if there are any…

Cornstalks
- 37,137
- 18
- 79
- 144
15
votes
6 answers
Representing dynamic typing in C
I'm writing a dynamically-typed language. Currently, my objects are represented in this way:
struct Class { struct Class* class; struct Object* (*get)(struct Object*,struct Object*); };
struct Integer { struct Class* class; int value; };
struct…

Imagist
- 18,086
- 12
- 58
- 77
11
votes
2 answers
Is there a single character day of the week convention?
Is there a single character convention for the days of the week in English (or programmer-specific) and if so what is it? I realize this could be an English language question but I think it has special significance for programmers.
Maybe something…

User
- 62,498
- 72
- 186
- 247
9
votes
3 answers
How to represent a binary tree with tables (html)?
Here is a brain-teaser for the brave. I've been at it for days and just can't come with the solution.
I wanted to come out with something like this:
Using html, CSS and PHP only.
I got near, but not quite what I expected. Here is the code in PHP…

Naoise Golden
- 8,793
- 4
- 49
- 65
9
votes
1 answer
In Perl 6, how can I convert from raw bytes to floating point using the NativeCall interface?
From this conversation in the Perl 6 IRC channel and a question posted by Martin Barth, I'm trying to reproduce this C code using the Perl6 NativeCall interface, which is used with that purpose. This is what I have tried:
use NativeCall;
my uint32…

jjmerelo
- 22,578
- 8
- 40
- 86
9
votes
3 answers
Efficiency: char array vs int array
I am programming a game and want to represent a board using an array. I am looking for efficiency since I am going to do many iterations. In this case, both an int array or a char array seem convenient for the board representation. Is there any…

PALEN
- 2,784
- 2
- 23
- 24
8
votes
4 answers
Does const_cast ever cause actual code emission?
Is it true that const_cast is just a way to tell the compiler "stop moaning, treat this as a non-const pointer"? Are there any cases when const_cast itself is translated into actual machine code?

sharptooth
- 167,383
- 100
- 513
- 979
8
votes
1 answer
How does OCaml represent lazy values at runtime?
This chapter in Real World OCaml describes the runtime memory layout of different data types. However, there is no discussion on lazy values.
How is lazy_t implemented, i.e., what does its runtime representation and what the key operations that are…

typesanitizer
- 2,505
- 1
- 20
- 44
7
votes
1 answer
Why does refactoring data to newtype speed up my haskell program?
I have a program which traverses an expression tree that does algebra on probability distributions, either sampling or computing the resulting distribution.
I have two implementations computing the distribution: one (computeDistribution) nicely…

Jonas Kölker
- 7,680
- 3
- 44
- 51
7
votes
3 answers
Pygraphviz / networkx set node level or layer
I have a dataset that represents a kind of genealogy tree. Each node has 2 parents (except first generation, they have no parents). For a given node, its parents can be from any previous generation. For example a node in generation n, can have a…

Dr Sokoban
- 1,638
- 4
- 20
- 34
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
6
votes
1 answer
Why does Octave round to 1 'earlier' than 0?
Context:
In Octave, I have written code for a Sigmoid function that returns values between 0 and 1; in an ideal world, it would only return 0 for -Inf and 1 for +Inf but due to floating point imprecision, values that are extremely close to either of…

Zac G
- 77
- 7