Sorry your browser is not supported!

You are using an outdated browser that does not support modern web technologies, in order to use this site please update to a new browser.

Browsers supported include Chrome, FireFox, Safari, Opera, Internet Explorer 10+ or Microsoft Edge.

DarkBASIC Professional Discussion / Binary Range Shifting

Author
Message
Shadow Robert
23
Years of Service
User Offline
Joined: 22nd Sep 2002
Location: Hertfordshire, England
Posted: 3rd May 2003 00:32
the attached code to an extent works, and partially why i want the community to see this right now - because although the technique works itself, when i made a function to achieve the same goal it failed - and i'm slightly baffled to why.

well that aside, its been bugging me the last week that i've not been able to grab a ranged value of bits within a value ... which no doubt most won't even know what i mean, let alone want to use it.

however i'm gonna quickly go over Binary Values, why we use them and why its been so important to finally figure out Bit Ranges

as ya'll know a Binary value is just a series of 1's and 0's
now this is packages into groups of 4 called a Binary String, which represent a value.
now there are currently 3 values it can represent, either
Decimal 0-9 (base 10)
Hexagonal 0-F (base 16)
Octogonal 0-7 (base 7 but is weird, and you'll probably never use it)

to make things simpler i'll be sticking to Decimal but as you get better Hex is probably better to use as it conforms to the setup of Binary Strings.

now as i said each value is either 0 or 1, which means you can only have 2 settings per bit/boolean (which is a single value in a Binary String)
we go from 0 and we add from that, you can think of this as very simplistic math if you like because
0000 = 0 ... 0001 = 1 however as we don't have a 2 we move to the next bit in the series 0010 = 2

now if we do all of the roll over numbers you will notice a pattern very quickly

0001 = 1 - 0010 = 2 - 0100 = 4 - 1000 = 8

you notice that? well as you have 2 values per bit, this means that each time you roll over to a new bit you've essentially double the value from the previous roll over - most of you should know that when a value does this, it is a Squared Number ... as each time it grows it grows by exactly 2

from this we can actually use the following maths to figure out how bit a value you can make from a bit
2^Bit = Size of Value

2^8 = 256 (byte)
2^16 = 65,535 (word)
2^32 = 4,294,967,296 (dword)

so what exactly does this have to do with bitshifting and ranging?
well basically its the foundation for the techniques.

see when you want to bitshift a value its to basically move a small bit of data from one area to another...
for example

0011 0100 now if we bitshift it left '>0 = 0110 1010 0100
value>>4 = 0110 1010
value>>8 = 0110

well this is all well and good for knowing what these total values are, but as we assume we don't know the values to extract them we have to figure out a was of getting each 4bits of data within the ranges we want

this is where Bit Rangine comes in

bit1=( value>>0-( (value>>(0+4)>4-( (value>>(4+4)>8-( (value>>(8+4)>startbit - ( ( value>>(startbit-range) )
Tsu'va Oni Ni Jyuuko Fiori Sei Tau!
One block follows the suit ... the whole suit of blocks is the path ... what have you found?
MrTAToad
23
Years of Service
User Offline
Joined: 26th Aug 2002
Location: United Kingdom
Posted: 3rd May 2003 00:52 Edited at: 3rd May 2003 01:15
Try using :



or



to start with!

However, why not use something like :



Yes, I know the last parameter isn't being used - but I dont really think its needed (its easy enough to use if you think it is).

The full modified code is thus :



Good news everyone! I really am THAT good...
http://www.nickk.nildram.co.uk/ for great plug-ins - oh my, yes!
Shadow Robert
23
Years of Service
User Offline
Joined: 22nd Sep 2002
Location: Hertfordshire, England
Posted: 3rd May 2003 02:15
there was a reason i wasn't doing it to 256 Toady

Tsu'va Oni Ni Jyuuko Fiori Sei Tau!
One block follows the suit ... the whole suit of blocks is the path ... what have you found?
MrTAToad
23
Years of Service
User Offline
Joined: 26th Aug 2002
Location: United Kingdom
Posted: 3rd May 2003 02:50
Thought so...

Good news everyone! I really am THAT good...
http://www.nickk.nildram.co.uk/ for great plug-ins - oh my, yes!
Shadow Robert
23
Years of Service
User Offline
Joined: 22nd Sep 2002
Location: Hertfordshire, England
Posted: 3rd May 2003 03:27


this works... with the exception of the final bit which has the whole value, not sure why
really need this to work else i can kiss my UINT system goodbye - annoying thing is i can get this working on C no problem, like this ->



wouldn't mind it being an operator within DBpro itself god knows what the operator would be, but the idea is to be able to pic any range of binaries you want...

so say you want a 5-6-5 jpg you'd do

red=BitRange(Colour,11,5)
green=BitRange(Colour,5,6)
blue=BitRange(Colour,0,5)



Tsu'va Oni Ni Jyuuko Fiori Sei Tau!
One block follows the suit ... the whole suit of blocks is the path ... what have you found?
MrTAToad
23
Years of Service
User Offline
Joined: 26th Aug 2002
Location: United Kingdom
Posted: 3rd May 2003 04:51
I think what its doing with the first is wrapping the bits around, instead of just chopping bits off

Good news everyone! I really am THAT good...
http://www.nickk.nildram.co.uk/ for great plug-ins - oh my, yes!
IanM
Retired Moderator
23
Years of Service
User Offline
Joined: 11th Sep 2002
Location: In my moon base
Posted: 3rd May 2003 05:11
What it's doing is signed maths, despite the fact that you're using dwords. It's the subtraction that's causing the problems.

Try this instead

Shadow Robert
23
Years of Service
User Offline
Joined: 22nd Sep 2002
Location: Hertfordshire, England
Posted: 4th May 2003 08:55
oh quality, cheers Ian (^_^)
you know i don't think i fully understand what the '&&' works... perhaps one of you guys could explain them to me better, i mean i say the explaination in the help but its a weak as my brother's tea

and i think i'm using then in the wrong way still cause i'm using them like they're AND - guess the Binary Operators work differently to the Value Opterators.

Tsu'va Oni Ni Jyuuko Fiori Sei Tau!
One block follows the suit ... the whole suit of blocks is the path ... what have you found?
IanM
Retired Moderator
23
Years of Service
User Offline
Joined: 11th Sep 2002
Location: In my moon base
Posted: 4th May 2003 13:47
The value operators AND/OR/NOT work using the whole value as a true/false value, when zero is false, and all other numbers are true.

The bitwise operators && || .. ~~ work on a bit-by-bit basic.

Basically, the code makes a mask of the number of bits specified in the range, so that when anded with your value, only bits within that range pass through.

0110001110010110 Source value
0000000011111111 Mask (8 bits) (2^8-1) => (256-1) => 255
0000000010010110 Final anded value

Actually, I thought it would be the mask that needed explaning if anything did
Shadow Robert
23
Years of Service
User Offline
Joined: 22nd Sep 2002
Location: Hertfordshire, England
Posted: 4th May 2003 14:13
oh i see thats cool, yeah that makes sense to why to use that then.
hehee and probably with normal people the mask would've been, but i have a strange way of looking at things (^_^)
always the basics i tend to have trouble with - i can now see why the value and binary operators won't work with each other

Tsu'va Oni Ni Jyuuko Fiori Sei Tau!
One block follows the suit ... the whole suit of blocks is the path ... what have you found?
APEXnow
Retired Moderator
23
Years of Service
User Offline
Joined: 15th Apr 2003
Location: On a park bench
Posted: 4th May 2003 14:32
It's also good for using Constant values that are defined for use with variables that hold multiple parameters for flags that can be used efficiently.

#constant OBJ_TEXTURED 1
#constant OBJ_CUBEMAP 2
#constant OBJ_ILLUMINATED 4
#constant OBJ_ANIMATED 8
#constant OBJ_STATIC 16

nObjState = OBJ_TEXTURED && OBJ_ANIMATED

If nObjState || OBJ_MIRRORED Then Set Cube Mapping On nObj, nTex1, .....

If nObjState || OBJ_STATIC
Rem Code for preventing object movement or something
EndIf

The point is that a single variable, using bitwise operators can hold many values.

Very handy

"Man who looses key to woman's appartment...... He get no nookie" - A wise chinese man.
Shadow Robert
23
Years of Service
User Offline
Joined: 22nd Sep 2002
Location: Hertfordshire, England
Posted: 4th May 2003 14:44
well i don't have a clue what your code is trying to do, personally for UINT operators i've been usign using + and then checking them against each other like in my FVF library.

wouldn't mind using the | symbol for it to be honest, i saw in something that Toady did he use the || but i didn't understand why.
i mean the way i saw it, i thought it ment->
if value = %10010000 or %01101010

but it really means
if value = (10010000+01101010) right?

Tsu'va Oni Ni Jyuuko Fiori Sei Tau!
One block follows the suit ... the whole suit of blocks is the path ... what have you found?
APEXnow
Retired Moderator
23
Years of Service
User Offline
Joined: 15th Apr 2003
Location: On a park bench
Posted: 4th May 2003 14:49 Edited at: 4th May 2003 14:51
Oops, soz Raven, I'm still C oriented but applying the operators correctly, the principals the same lol Adding the values is the same as Or-ing but I used the Or-ing for value assignment rather than conditional checking

"Man who looses key to woman's appartment...... He get no nookie" - A wise chinese man.
APEXnow
Retired Moderator
23
Years of Service
User Offline
Joined: 15th Apr 2003
Location: On a park bench
Posted: 4th May 2003 14:59 Edited at: 4th May 2003 15:00
I'm sure you're familiar with C/C++ but the way I used it was.

#define OBJ_TEXTURED 0x01
#define OBJ_CUBEMAPPED 0x02
#define OBJ_ILLUMINATED 0x04
#define OBJ_ANIMATED 0x08
#define OBJ_STATIC 0x10
#define OBJ_UNUSED 0x12

int nObjFlags = 0;

nObjFlags = OBJ_TEXTURED || OBJ_CUBEMAPPED || OBJ_STATIC;

if( nObjFlags && OBJ_TEXTURED)
{
// Texture object
}

n so on. Very crude explanation but its worked for me lol

"Man who looses key to woman's appartment...... He get no nookie" - A wise chinese man.
Shadow Robert
23
Years of Service
User Offline
Joined: 22nd Sep 2002
Location: Hertfordshire, England
Posted: 4th May 2003 15:03
yeah, well i'm getting most of my operator information form C right now ... hey has anyone noticed that when you create a program that uses nothing but standard operators and core functions that the program starts instantly?



whereas you add to that something like



and suddenly it takes a good 5seconds to load... i know it has nothing to do here, but just thought it was weird

Tsu'va Oni Ni Jyuuko Fiori Sei Tau!
One block follows the suit ... the whole suit of blocks is the path ... what have you found?
Shadow Robert
23
Years of Service
User Offline
Joined: 22nd Sep 2002
Location: Hertfordshire, England
Posted: 4th May 2003 15:05 Edited at: 4th May 2003 15:06
yeah except i'd do this line
int nObjFlags = 0;

nObjFlags = OBJ_TEXTURED || OBJ_CUBEMAPPED || OBJ_STATIC;

like...
int nObjFlags = (OBJ_TEXTURED | OBJ_CUBEMAPPED | OBJ_STATIC );

guess its a bad habit picked up from DirectX programming

Tsu'va Oni Ni Jyuuko Fiori Sei Tau!
One block follows the suit ... the whole suit of blocks is the path ... what have you found?
APEXnow
Retired Moderator
23
Years of Service
User Offline
Joined: 15th Apr 2003
Location: On a park bench
Posted: 4th May 2003 15:09
LOL, yeah, know the feeling...

The program slowdown I thought was due to the fact that the program dynamically links to the DB engine depending on what you use in the program, maybe adding the extra code causes runtime linking with a larger DLL than the first example, hence slowing down initialization. Just a thought though.

"Man who looses key to woman's appartment...... He get no nookie" - A wise chinese man.
Shadow Robert
23
Years of Service
User Offline
Joined: 22nd Sep 2002
Location: Hertfordshire, England
Posted: 4th May 2003 15:46
yeah i think your right... makes you wonder how the language is actually setup under the hood so to speak

Tsu'va Oni Ni Jyuuko Fiori Sei Tau!
One block follows the suit ... the whole suit of blocks is the path ... what have you found?
APEXnow
Retired Moderator
23
Years of Service
User Offline
Joined: 15th Apr 2003
Location: On a park bench
Posted: 4th May 2003 16:06
All the DLLs appear modular depending on the components you use, creating the object starts up DX initialization too I suppose. Not related but another thing I've found to speed up execution is disable any virus resident apps that auto check apps before running, you won't believe the time it took running DB apps before I disabled it LOL

"Man who looses key to woman's appartment...... He get no nookie" - A wise chinese man.
IanM
Retired Moderator
23
Years of Service
User Offline
Joined: 11th Sep 2002
Location: In my moon base
Posted: 4th May 2003 18:06
The reason that startup time is longer the more DBPro facilities you use is that as well as calling the startup code for each DLL included, it also has to unpack them first.

On Win2K, it unpacks the DLL's to C:\Documents and Settings\<UserID>\Local Settings\Temp\dbpdata, and when you include any 3D, it includes *all* the 3D DLL's.
Shadow Robert
23
Years of Service
User Offline
Joined: 22nd Sep 2002
Location: Hertfordshire, England
Posted: 4th May 2003 20:59
yeah WinXP also unpacks them to the same place, one each time its called - i have 48 in my temp directory before i cleared it, and thats just from today.

Tsu'va Oni Ni Jyuuko Fiori Sei Tau!
One block follows the suit ... the whole suit of blocks is the path ... what have you found?

Login to post a reply

Server time is: 2026-07-11 10:25:46
Your offset time is: 2026-07-11 10:25:46