Jump to content
IGNORED

Integers: I'm confused


Words Fail

Recommended Posts

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. 

  • Like 1
Link to comment
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
  • Like 2
Link to comment
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?

Link to comment
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

  • Like 1
Link to comment
Share on other sites

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.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

Loading...
  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...