Why are the X and Y index registers 8-bit? - 6502

I have been trying to get into 6502 programming, and something isn't adding up. If it has a 16-bit address space, why are the X and Y index registers 8-bit? Are they used in tandem, where X is the lower byte and Y is the higher byte of the address? If so how would that work?

So I thought about and the answer is simpler than I thought. The index registers simply add to the base address (so LDA $0200, X will add X to 0x0200). If one wants to use a larger index register they can use indirect addressing. :)

Related

what is odd and even subsampling in ov5640?

I'm working on ov5640 MIPI sensro, while going through the document, I found terms odd subsampling and even subsampling.
I could not able to find any information on them in same document, but I found subampling concept in AR0330CM data sheet where they mentioned that
"""
The sensor increments its x and y address based on the
x_odd_inc and y_odd_inc value. The value indicates the
addresses that are skipped after each pair of pixels or rows
has been read.
The sensor will increment x and y addresses in multiples
of 2
"""
x_subsampling_factor = (1+x_odd_inc)/2
y_subsampling_factor = (1+y_odd_inc)/2
From there I'am able to understand the concept of subsampling odd_inc but what is even_inc?

How to convert values to N bits of resolution in MATLAB?

My computer uses 32 bits of resolution as default. I'm writing a script that involves taking measurements with a multimeter that has N bits of resolution. How do I convert the values to that?
For example, if I have a RNG that gives 1000 values
nums = randn(1,1000);
and I use an N-bit multimeter to read those values, how would I get the values to reflect that?
I currently have
meas = round(nums,N-1);
but it's giving me N digits, not N bits. The original random numbers are unbounded, but the resolution of the multimeter is the limitation; how to implement the limitation is what I'm looking for.
Edit I: I'm talking about the resolution of measurement, not the bounds of the numbers. The original values are unbounded. The accuracy of the measured values should be limited by the resolution.
Edit II: I revised the question to try to be a bit clearer.
randn doesn’t produce bounded numbers. Let’s say you are producing 32-bit integers instead:
mums = randi([0,2^32-1],1,n);
To drop the bottom 32-N bits, simply divide by an appropriate value and round (or take the floor):
nums = round(nums/(2^(32-N)));
Do note that we only use floating-point arithmetic here, numbers are integer-valued, but not actually integers. You can do a similar operation using actual integers if you need that.
Also, obviously, N should be lower than 32. You cannot invent new bits. If N is larger, the code above will add zero bits at the bottom of the number.
With a multimeter, it is likely that the range is something like -M V to M V with a a constant resolution, and you can configure the M selecting the range.
This is fixed point math. My answer will not use it because I don't have the toolbox available, if you have it you could use it to have simpler code.
You can generate the integer values with the intended resolution, then rescale it to the intended range.
F=2^N-1 %Maximum integer value
X=randi([0,F],100,1)
X*2*M/F-M %Rescale, divide by the integer range, multiply by the intended range. Then offset by intended minimum.

How to combine CRC-32 results?

Let's say I have two numbers X = 0xABC; Y = 0xDE.
I want to calculate CRC-32 over Z, which is X concatenated to Y i.e. Z = 0xABCDE.
I have CRC(X) and CRC(Y) available. How can I compute CRC(Z) ?
Take a look at crc32_combine() in zlib for the approach.
The basic idea is to use the linearity of CRCs. The CRC of 0xABC00 exclusive-or'ed with 0x000DE is the exclusive-or of their corresponding CRCs. If I ignore the pre and post-processing (which I can for reasons that are left to the reader to derive), leading zeros do not change the CRC, so the CRC of 0xDE is the same as the CRC of 0x000DE. So all I need to do is calculate the effect of appending zeros when starting with the CRC of 0xABC, in order to get the CRC of 0xABC00. Then exclusive-or those two CRCs.
crc32_combine() uses matrix multiplication to compute the effect of appending n zeros in O(log(n)) time instead of O(n) time, so combining CRCs is very fast regardless of the lengths of the original messages.

Universal Hashing Integers

This is my first thread here and I would like to ask you a couple of questions for universal hashing of integers.
A universal hashing algorithm is supposed to use this:
equation =
((a*x+b)mod p) mod m
a=random number from 1 to p-1
b=random number from 0 to p-1
x= the Key
p= a prime number >=m
m=the size of the array
I know the numbers I am going to hash are on the range of 1-2969.
But I cannot understand how to use this equation in order to make as low collisions as possible.
At the time a and b are random I cannot do anything about it.
My question is how I am supposed to pick the prime if I have more than one choice, the range of primes I can use are from 2 to 4999.
I tried to pick the first available that corresponds the requirements for the function but sometimes it can return negative numbers. I have searched on Google and Stackoverflow but I could not figure out what I am not doing wrong.
I am coding in C. Also, I can use only universal hashing.
Thank your for your time.

how to get reverse(not complement or inverse) of a binary number

I am implementing cooley-tuckey fft(raddix - 2 DIF / DIT) algorithm in matlab.In that for the bit reversing i want to have reverse of an binary number. so can anyone suggest how can I get the reverse of a binary number(like 100111 -> 111001). One who have worked on fft implementation can help me with the algorithm also.
Topic: How to do bit reversal in Matlab? .
If you're using double precision floating point ('double') numbers
which are integers, you can do this:
dr = bin2dec(fliplr(dec2bin(d,n))); % Bits in dr are in reverse order
where n is the number of bits to be reversed and where 0 <= d < 2^n.
You will experience no precision problems at all as long as the
integers are no more than 52 bits long.
And
Re: How to do bit reversal in Matlab?
How large will the numbers be that you need to reverse? May I ask what
is the purpose of it? Maybe there is a more efficient way to solve the
whole problem. If the numbers are large you can just store the bits as
a string. To reverse it just read the string backwards! Or use
fliplr().
(There may be better places to ask).
If it were VHDL I'd suggest an alias with 'REVERSE'RANGE.
Taken from the help section;
Y = swapbytes(X) reverses the byte ordering of each element in array X, converting little-endian values to big-endian (and vice versa). The input array must contain all full, noncomplex, numeric elements.