Questions tagged [internal-representation]

23 questions
235
votes
19 answers

Why prefer two's complement over sign-and-magnitude for signed numbers?

I'm just curious if there's a reason why in order to represent -1 in binary, two's complement is used: flipping the bits and adding 1? -1 is represented by 11111111 (two's complement) rather than (to me more intuitive) 10000001 which is binary 1…
Ray
  • 3,468
  • 8
  • 26
  • 27
52
votes
5 answers

What's the size cost of Java inheritance?

There are various articles out there on the interwebs that try to empirically estimate the overhead of a java.lang.Object in particular JVM implementations. For example, I've seen the size overhead of a bare Object estimated at 8 bytes in some…
0xbe5077ed
  • 4,565
  • 6
  • 35
  • 77
14
votes
7 answers

int((0.1+0.7)*10) = 7 in several languages. How to prevent this?

Recently I came across a bug/feature in several languages. I have a very basic knowledge about how it's caused (and I'd like some detailed explanation), but when I think of all the bugs I must have made over the years, the question is how can I…
cypher
  • 6,822
  • 4
  • 31
  • 48
13
votes
11 answers

Boolean true - positive 1 or negative 1?

I'm designing a language, and trying to decide whether true should be 0x01 or 0xFF. Obviously, all non-zero values will be converted to true, but I'm trying to decide on the exact internal representation. What are the pros and cons for each choice?
zildjohn01
  • 11,339
  • 6
  • 52
  • 58
11
votes
1 answer

What is the internal representation of datetime in sql server?

What is the underlying datastructure of datetime values stored in SQL Server (2000 and 2005 if different)? Ie down to the byte representation? Presumably the default representation you get when you select a datetime column is a culture specific…
Ray
  • 3,468
  • 8
  • 26
  • 27
8
votes
3 answers

How is a partial application represented at runtime?

When I write something like map (1+) list in Haskell, what is the internal representation of (1+)? Since it is a partial application of (+), the argument 1 has to be saved somewhere, but I can't get my head around this. Can somebody give me a brief…
fuz
  • 88,405
  • 25
  • 200
  • 352
7
votes
4 answers

Result of sizeof for C++ arrays and pointers

On an x86_64 architecture, a pointer is 8 bytes. It makes sense to me that sizeof(x) should return 8. I understand that a char is a single byte, and 5 bytes is the size of array z. What is the intuition behind why sizeof(z) does not return 8? int* x…
4
votes
1 answer

How does R represent NA internally?

R seems to support an efficient NA value in floating point arrays. How does it represent it internally? My (perhaps flawed) understanding is that modern CPUs can carry out floating point calculations in hardware, including efficient handling of…
Szabolcs
  • 24,728
  • 9
  • 85
  • 174
3
votes
1 answer

How does Haskell runtime represent lazy values?

I don't even know how to express this question. A assume there's a pointer to a non evaluated expression. If it's requested (by some strict function that coerces it) then the pointer value is replaced by the value evaluated. Right? Am I wrong? So I…
caeus
  • 3,084
  • 1
  • 22
  • 36
3
votes
1 answer

Can "bigger than 0.0" control show different behaviors on different systems?

Below control of bigger than 0.0 for a double variable works correctly. I am curious about whether the compiled exe with this function could behave differently on different systems. bool MyFunction(double x) { if (x > 0.0) return true;…
KC_
  • 89
  • 11
2
votes
4 answers

How are timeouts represented in JavaScript?

When I call set timeout it returns a number, for example > setTimeout(function(){ console.log('done'); },1000); 4431 "done" I know that I can use this number to call clearTimeout() but what does this number represent internally?
Greg Guida
  • 7,302
  • 4
  • 30
  • 40
2
votes
1 answer

Excess (-1) in base 4 representation

I've been trying to wrap my head around this one problem for the last couple of days, and I can't figure out a way to solve it. So, here it goes: Given the base 4(that is 0, 1, 2, 3 as digits for a number), find the excess (-1) in base 4…
1
vote
1 answer

How can I see the actual binary content of a VB6 Double variable?

I have hunted about quite a bit but can't find a way to get at the Hexadecimal or Binary representation of the content of a Double variable in VB6. (Are Double variables held in IEEE754 format?) The provided Hex(x) function is no good because it…
Wojja62
  • 76
  • 5
1
vote
1 answer

Python numpy.divmod and integer representation

I was trying to use numpy.divmod with very large integers and I noticed a strange behaviour. At around 2**63 ~ 1e19 (which should be the limit for the usual memory representation of int in python 3.5+), this happens: from numpy import divmod test =…
pazqo
  • 477
  • 3
  • 9
1
vote
2 answers

Trying to find a good data representation for a genetic (evolutionary) algorithm, but I just can't imagine one

Disclaimer First of all, this is for homework, so don't ask why it's so contrived, it is this way and it can only be this way. (I get a lot of "how about if you change something"), sorry ... I can't. Also I must use evolutionary algorithms, that…
1
2