IGNORED

# Integers: I'm confused

## Recommended Posts

I would like something to go up by 0.25. Then I need to check later for 1.00, 1.25, 1.50, 1.75, and 2.00. What do I need to dim?

dim speed = a.b

The whole page on 4.4 and 8.8 confuses me. I think it should say something like this is an example of a few 4.4.. and this is an example of a few 8.8

##### Share on other sites

I think I did something similar in trying to make acceleration in one game where I would do something like

if joy0right then b=b+25

and then I would do something like

if b=100 then a=a+1:b=0

There are probably other ways to do this but it seemed to work for this purpose.

##### Share on other sites

the fractional part is still just a byte
it can reperesent 256 values, 0..255 inclusive
as a .8 fraction (8 is the number of bits in a byte)
a byte is the integer number of 256ths (1/256)
1 = 256 256ths
.25 = 256 * .25 = 64
for 0.25 you have two bytes 0 and 64
ie the fractional byte will equal 64
this will be relatively neat in your case because youre
looking for multiples of a power of two
so eg .25 (a power of 2, 2^-2) is an integer number of 256ths

if you want to test for 1.5 it will be 1 and .5 * 256 = 128

if a = 1 && b = 128 then [do something]

for non powers of two it gets messier
0.33 is 84.48 256ths ie .33 * 256 = 84.48 and bB rounds it to 84

personally I'd dim it as b.a because the variables are in order
in memory and the processor is little endian and expects
a 16 bit quantity to be in order in memory with the least byte first
but that has nothing to do with what you're doing

Edited by bogax
##### Share on other sites

1 hour ago, bogax said:

personally I'd dim it as b.a because the variables are in order
in memory and the processor is little endian and expects
a 16 bit quantity to be in order in memory with the least byte first
but that has nothing to do with what you're doing

Out of curiosity, would doing this result in some space saved? Less cycles?

##### Share on other sites

Never tried the a.b whatever thing as my brain can't handle it.

I usually have a main counter that goes up by one each main game loop:

main

counter = counter + 1

If I want something to happen every four iterations of the main loop I do this:

if counter&3 = 0 then goto everyforthdothis

That takes the counter that goes from 0 - 255 to something like 0 1 2 3 0 1 2 3 0 1 2 3 ..

If you wanted something to happen every other iteration of the main loop you can just check the first bit in the counter since it always flips each time:

if counter{0} then goto otherframe

## Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

×   Pasted as rich text.   Paste as plain text instead

Only 75 emoji are allowed.