Login
Username:

Password:

Remember me



Lost Password?

Register now!

Sections

Who's Online
90 user(s) are online (84 user(s) are browsing Forums)

Members: 2
Guests: 88

FlynnTheAvatar, LiveForIt, more...

Support us!

Headlines

 
  Register To Post  

bits functions (set, unset, test)
Quite a regular
Quite a regular


See User information
I've checked over the net and on my C book to understand how I can set/clear or test a bit in an int value but it remain unclear for me :(

I've found how to test !

int TestBit( int Var, int itID ){
return Var & ( 1<<BitID );
}

But not how to set/clear.

Can someone help me ?

EDIT :
I think I've found a solution :


void SetBit( int *Var, int BitID ){
*Var = *Var | ( 1<<BitID );
}

void ClearBit( int *Var, int BitID ){
*Var = *Var ^ ( 1<<BitID );
}

Do you think it's correct ?


Regards,
Freddix / AmiDARK


Edited by freddix on 2009/12/4 22:02:28
Edited by freddix on 2009/12/4 22:44:06
Edited by freddix on 2009/12/4 22:45:20
All we have to decide is what to do with the time that is given to us.
Go to top
Re: bits functions (set, unset, test)
Just popping in
Just popping in


See User information
@freddix

Hi Amidark,

I am happy to see you that you are still working after the Alchimee.

As I told you there, I will be glad to help and I am going to do it.
Your functions work !!!

Best regards,
A+,
Yescop/Jes?s

Since a lot of months without an amiga to love, I was lost.
Now I feel happiness again with a Sam Flex 800 .
Go to top
Re: bits functions (set, unset, test)
Just popping in
Just popping in


See User information
@freddix

Quote:

freddix wrote:
I've checked over the net and on my C book to understand how I can set/clear or test a bit in an int value but it remain unclear for me :(

I've found how to test !

int TestBit( int Var, int itID ){
return Var & ( 1<<BitID );
}

But not how to set/clear.

Can someone help me ?

EDIT :
I think I've found a solution :


void SetBit( int *Var, int BitID ){
*Var = *Var | ( 1<<BitID );
}

void ClearBit( int *Var, int BitID ){
*Var = *Var ^ ( 1<<BitID );
}

Do you think it's correct ?


Regards,
Freddix / AmiDARK


The ClearBit function you've got is actually a toggle bit function. If you call it twice on the same variable with the same bit you end up with what you started out with. Also the test bit doesn't return a 1 on true. The correct versions are as follows:
void ClearBitint *Var, int BitID ){
   *Var = *Var & ~( 
1<<BitID );
}

int TestBit(int Var, int BitID ){
   return ((Var>>
BitID) & 1);
}


If you're using C++ you can use std::bitset instead though. That'll save you from having to think about it.

Go to top
Re: bits functions (set, unset, test)
Home away from home
Home away from home


See User information
@freddix Quote:
void ClearBit( int *Var, int BitID ){
*Var = *Var ^ ( 1<<BitID );
}

As pointed out, this toggles the bits, not clear them. I could instantly tell you how to clear a bit in E, but my C is a bit rusty so not all these brackets may be required:

void ClearBit( int *Var, int BitID ){
*Var = *Var & (~( 1<<BitID ));
}

edit: Ooops, hadn't noticed that Samurai_Crow had actually posted corrected versions.

Author of the PortablE programming language.
Go to top
Re: bits functions (set, unset, test)
Quite a regular
Quite a regular


See User information
@Samurai_Crow
Ok
Thank you for these changes.
I will test them today :)


@yescop:
Yes, the project continue.
I don't tell all news and progress because I do small things by small things and it could take too much post to tell everything each time ..
Here is my dev log from alchimie to now :

(translated by google cos I don't have time now to translate it manually :p, the original is in French ) :
Quote:

2009.12.04:
------------
- Addition of internal management functions of bits (set / clear / test)
- Added function DESyncMask () and its management in the Proceedings of cameras.

2009.11.29:
------------
- Added playback functions of free memory
- Added functions to enable / disable the Escape key to exit the application.
- Placing orders DESyncOn () DESyncOff () DESyncRate (VAL);

2009.11.27:
------------
- Fix the glClear mode multi-cameras to delete only the area of the current camera.

2009.11.25:
------------
- Added timer.device to manage functions of frame rate and animations.
- Added functions DEScreenFPS () and DEStatistics ()

2009.11.23:
-----------
- Improved user function DEKeyState ()
- Improved internal function MyKeyboardFunc () management via the keyboard MiniGL.
- Fix for managing the backdrop for the cameras not to erase the traces Basic2D.
- Added function: DEBoxEx (Left, Top, Right, Bottom, Color1, Color2, color3, color4)
- Added support for background color cameras (Backdrop)
- Added support for the close button of window to exit the application.
- Addition of various orders of "core".

2009.11.11:
------------
- If object 3D insensitive to light, turning off the global illumination on the object.


2009.11.08:
-----------
- Amendments to applications textures to match DarkBASIC Professional
- Change the camera to move as default DarkBASIC Professional
- Change the camera to move as default DarkBASIC Professional

2009.11.03:
-----------
- Added support for various keyboard functions (scancode, Keystation, special keys: up, down, left, right, function keys F1 to F12

2009.10.25;
-----------
BASIC 3D
- Added command: DEScrollObjectTexture (ObjectID, Uf, Vf)
- Added command: DEScaleObjectTexture (ObjectID, XScale.f, yScale f)

2009.10.17:
-----------
BASIC 3D
- Added support for bilinear / trilinear / no filtering on 3D objects.
- Added support for extra propoerties (fog, light, ambient 3D objects sensitivity)
- Added support for object Ambience, Specular, Diffuse and Emissive Properties functions.
SETUP
- Added support for switching from windowed to fullscreen and reverse.

2009.10.16:
------------------
BASIC 3D
- Added support for Ghost Object functions (On / Off Ex with support for dark ghost mode too)
- Added support for ScaleObject () function
IMAGE
- Added DrawToFront & DrawToBack priority function to change between 2D and 3D drawing.

2009.10.12:
------------------
BASIC 3D
- Added support for transparency using BLENDING command set: Set One Alpha Mapping.

2009.10.05:
------------------
BASIC 3D
- Fixed Camera & Objects rotation to be the same than Default DarkBASIC Professional ones.
- Added support for 3D Objects bodies.

2009.10.05:
------------------
FILE
- Added support for FILES command set (OpenToRead, OpenToWrite, Close, MakeMemblockFromfile)


2009.09.01:
-----------------
Basic3D
- Support for Loading Images as Images & Textures
- Support for Objects Texturing, Lighting (Light 0) Normals.
LIGHTS
- Adding Ambient light support
IMAGE
- Adding some IMAGE command set
MEMBLOCK
- Adding some MEMBLOCK command set
SYSTEM
- Internal structure object development.

All we have to decide is what to do with the time that is given to us.
Go to top
Re: bits functions (set, unset, test)
Just popping in
Just popping in


See User information
@freddix

Impressive your work !!! Go on !!

A+,
Yescop

Since a lot of months without an amiga to love, I was lost.
Now I feel happiness again with a Sam Flex 800 .
Go to top
Re: bits functions (set, unset, test)
Quite a regular
Quite a regular


See User information
Thank you for the changes in my functions.
Now the Sync Mask CAMERAMASK work perfectly :)

All we have to decide is what to do with the time that is given to us.
Go to top
Re: bits functions (set, unset, test)
Home away from home
Home away from home


See User information
@freddix

Glad to see your progress, keep it like that :) Have any planes (date or kind) when you will add basic "sound" support (just mp3 maybe for begining) ?

Join us to improve dopus5!
AmigaOS4 on youtube
Go to top
Re: bits functions (set, unset, test)
Quite a regular
Quite a regular


See User information
@kas1e
in fact, I don't know ...
I progress on "feeling".
That mean .. that I develop things in a total chaotic order .. Sound can be the next thing I'll start to work ... or maybe not ...

However, I should add 2D / 3D sound support soonly because it's not the hardest task to do :p

Regards,
Freddix / AmiDARK

All we have to decide is what to do with the time that is given to us.
Go to top

  Register To Post

 




Currently Active Users Viewing This Thread: 1 ( 0 members and 1 Anonymous Users )




Powered by XOOPS 2.0 © 2001-2024 The XOOPS Project