this post was submitted on 04 Oct 2024
4 points (83.3% liked)

The C Programming Language

632 readers
10 users here now

Everything related to the C programming language.

founded 5 years ago
MODERATORS
 

Second representation requires at least 6 bits to represent numbers between 0 to 59. But 5 bits are not just enough - 2^5^ = 32, which can only represent from 0 up to 31 seconds.

According to K.N. King:

You may be wondering how it 's possible to store the seconds - a number between 0 and 59 in a field with only 5 bits. Well. DOS cheats: it divides the number of seconds by 2, so the seconds member is actually between 0 and 29.

That really makes no sense?

you are viewing a single comment's thread
view the rest of the comments
[–] velox_vulnus@lemmy.ml 3 points 1 day ago (2 children)

This seems to be the likely answer. I'm assuming that it has something to do with the technological limitation of 16 bit. 1981 saw the first 32-bit non-x86 microprocessor (Intel iAPX 432), and MS-DOS was released for 16-bit in mind, like the 8086. Perhaps, the highest size of the integer was limited to 16 bit as well, and with that in mind, they had to make sure to create a non-padded struct for time, in which the hour were allotted 5 bits (= 32 ≈ 24hour), minutes were allotted 6 bits (= 64 ≈ 60mins). The last remaining 5 bits were assigned to seconds, and with the remaining bit-fields, the best precision they could come up with gave a 2-second interval. Is that a fair reasoning?

That's how I read it, yeah.

[–] Thorry84@feddit.nl 2 points 1 day ago (1 children)

Actually versions of MS-DOS were released for the MSX platform, which had a 8-bit Zilog Z80 CPU.

The number of bits mentioned when referring to processors usually refer to the size of the internal registers. You'll find that it doesn't actually matter how big the internal registers are. This just matters for the number of bits possible to process at the same time. So in order to process more bits, it just takes more steps, but it isn't impossible.

Pretty sure no one here was worried about what was or wasn't possible, just the method that was used in this specific instance.