chummersone / chummersone.github.io

MIT License
11 stars 1 forks source link

Extend to arbitrary word length #1

Closed MohrMa2 closed 2 years ago

MohrMa2 commented 2 years ago

I stumbled across the Q-format converter, which came very handy.

What is missing, is special formats, like signed Q19.4 or similar, where the word size is not a multiple of byte.

Is the source code available?

chummersone commented 2 years ago

The conversion is performed by the rather inelegant JavaScript, which you can review by looking at the page source. Also, Q19.4 corresponds to a 24-bit number, which is already supported.

MohrMa2 commented 2 years ago

Yeah you are right in this case. But sometimes, I have really arbitrary formats, signed Q8.2 or unsigned Q14.0 similar. But I will check the code and try to solve it.

chummersone commented 2 years ago

In hindsight, rather than tinkering with JS, what you need can probably be achieved by simply changing the HTML form control that chooses the number of bits. See <select id="num_bits"> on line 787.

MohrMa2 commented 2 years ago

I glimpsed over the code and had the same idea. Was not sure, if in JS maybe the usual bit length are implicitly assumed. But I will try and hope, the code is generic enough.

Thanks for your help. And, man you are fast in replying.

chummersone commented 2 years ago

I had a quick look over the code and I don't see any specific assumptions related to bytes; everything seems to be based on the number of bits. The only exception appears to be when displaying results in hex; I couldn't say for certain whether the sign bit will be extended through the most-significant nybble, but I doubt it. Note also that JS integers are 32-bit, which is the ceiling on the bit count.