Page 1 of 1

Can someone explain these number conversions

Posted: Fri Dec 11, 2020 2:26 pm
by Alex
In several programs the values are stored like the numbers in the third column. How are these numbers converted?

Dec Hex ???
1 1 8100
2 2 8200
3 3 8240
4 4 8300
5 5 8320
6 6 8340
7 7 8360
8 8 8400
9 9 8410
10 A 8420
11 B 8430
12 C 8440
13 D 8450
14 E 8460
15 F 8470
16 10 8500
17 11 8508
18 12 8510
19 13 8518
20 14 8520
21 15 8528
22 16 8530
23 17 8538
24 18 8540
25 19 8548
26 1A 8550
27 1B 8558
28 1C 8560
29 1D 8568
30 1E 8570
31 1F 8578
32 20 8600
33 21 8604
34 22 8608
35 23 860c
36 24 8610
37 25 8614
38 26 8618
39 27 861c
40 28 8620
41 29 8624
42 2A 8628
43 2B 862c
44 2C 8630
45 2D 8634
46 2E 8638
47 2F 863c
48 30 8640
49 31 8644
50 32 8648
51 33 864c
52 34 8650
53 35 8654
54 36 8658
55 37 865c
56 38 8660
57 39 8664
58 3A 8668
59 3B 866c
60 3C 8670
61 3D 8674
62 3E 8678
63 3F 867c
64 40 8700
65 41 8702
66 42 8704
67 43 8706
68 44 8708
69 45 870a
70 46 870c
71 47 870e
72 48 8710
73 49 8712
74 4A 8714
75 4B 8716
76 4C 8718
77 4D 871a
etc

Re: Can someone explain these number conversions

Posted: Thu Jul 15, 2021 7:37 pm
by Richard Bos
It's weird. They're clearly four-digit hex numbers, and if you plot them, you get something that looks somewhat like a jagged, simplified attempt at creating an exponential graph using integers only. Are they perhaps used in sound generation? Frequencies are exponential, after all.

What baffles me most are the gaps. Why do the numbers skip to the next 0x100 when reaching 0x80?

Re: Can someone explain these number conversions

Posted: Sun Jul 18, 2021 4:40 pm
by Alex
I only printed a part . The value goes from 1 to 255, If you convert the hexnumbers from the last column to decimal numbers and you look at the gaps the difference between the numbers is as follows from 1 to 255:

1x256
2x64
4x32
8x16
16x8
32x4
64x2
128x1

The numbers are used for various values in text adventures games instead of the usual decimal or hexadecimal numbers for 1 to 255. I guess there must be some mathematical conversion to get these 4 digit hex numbers as it is clearly some sequence if you look at the gaps, but I don't know which.

Re: Can someone explain these number conversions

Posted: Thu Jul 22, 2021 5:17 pm
by Richard Bos
Alex wrote:
Sun Jul 18, 2021 4:40 pm
I only printed a part . The value goes from 1 to 255, If you convert the hexnumbers from the last column to decimal numbers and you look at the gaps the difference between the numbers is as follows from 1 to 255:

1x256
2x64
4x32
8x16
16x8
32x4
64x2
128x1
That makes it even odder - though it might be just an oversight by the implementor. You see, after 1x256, I would expect 2x128, and so on; or, reversely, I would have expected 1x128 as the first gap. But this is a gap - and only the one - within the gaps! Very odd.

Or maybe not odd at all? Maybe the first gap is 128? Because, you see, between the last of the, say, 16x8 (which is 0x8570 to 0x8578) and the first of the 32x4 (0x8600 to 0x8604) there is yet another gap of 128! That is, we get the groups you describe above; but with a meta-gap of 128 between the groups. So in fact it is

1 x 128
gap of 128
2 x 64
gap of 128
4 x 32
gap of 128
all the way to
64 x 2
gap of 128
128 x 1

This makes the pattern regular again... but no less mysterious.
The numbers are used for various values in text adventures games instead of the usual decimal or hexadecimal numbers for 1 to 255. I guess there must be some mathematical conversion to get these 4 digit hex numbers as it is clearly some sequence if you look at the gaps, but I don't know which.
Well, it still looks pseudo-logarithmic to me, but the real question is why? I've never seen this before. In which games did you find these? And is the source code available? I might be able to glean something from how it is actually used, and in what situation; but frankly, from the numbers themselves, I can't say much.

Intriguing. Very intriguing.

Re: Can someone explain these number conversions

Posted: Sat Jul 24, 2021 9:39 am
by Alex
Richard Bos wrote:
Thu Jul 22, 2021 5:17 pm
In which games did you find these? And is the source code available?
Good question . Unfortunately I don't remember all games (I encountered at least around 20 games like that). However after searching several hours among my notes I found 1 :) :

Return to Karven

This game originally has been programmed in Basic. I manually detokenized part of the code (see attachment).
detokenized.zip
(16.79 KiB) Downloaded 39 times
It seems to be compiled and that he compiler is the reason the roomnumbers have been converted to these numbers.

If you enter the machine code monitor while playing you will find the location on address 60B9 and 60BA . The value is 8670 for the starting location.
I do have a list of all the rooms and their numbers if this could help.

Re: Can someone explain these number conversions

Posted: Sun Jul 25, 2021 4:04 pm
by Richard Bos
Ooh, a Commodore game. I've never had anything to do with the Commie and don't have an emulator for it - being firmly a Spectrum man myself. I could have a look at it, but I'm afraid I'd be starting from scratch and would mainly be guessing.

Re: Can someone explain these number conversions

Posted: Mon Jul 26, 2021 9:39 am
by Alex
No problem. I don't remember if I encountered this only with c64 games. I play games on all kinds of platforms. If I encounter this with a Speccy game I'll let you know.