CCS C Software and Maintenance Offers
FAQFAQ   FAQForum Help   FAQOfficial CCS Support   SearchSearch  RegisterRegister 

ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 

CCS does not monitor this forum on a regular basis.

Please do not post bug reports on this forum. Send them to CCS Technical Support

Bitwise Masking wont work Please help !

 
Post new topic   Reply to topic    CCS Forum Index -> General CCS C Discussion
View previous topic :: View next topic  
Author Message
deltatech



Joined: 22 Apr 2006
Posts: 87

View user's profile Send private message

Bitwise Masking wont work Please help !
PostPosted: Wed Aug 16, 2006 1:07 pm     Reply with quote

Hi All i want to extract from this number

19495316080623

194953

and also

1606

I have tried to use bitwise and but it doesnt work .

Can any please tell me what i am doing wrong ?

Thanks in advance

Code:
#include "F:\Program Files\PICC\Project\MSF\Mask.h"


void main()
{
int  received number=19495316080623
 

int time
int date

time=19495316080623&FFFFFF;

date=19495316080623&000000ff00ff00;

printf(%d,time);
 
printf(%d,date);


}
rberek



Joined: 10 Jan 2005
Posts: 207
Location: Ottawa, Canada

View user's profile Send private message

PostPosted: Wed Aug 16, 2006 1:40 pm     Reply with quote

Normally you perform a bitwise AND on two numbers with a similar radix (i.e. both hex). I'm guessing that doing this with a decimal integer and a hex number means the compiler will likely convert the decimal integer to a hex value, do the AND, then the printf will turn the hex value in to an integer, which will look nothing like your expected result.

In addition, looking at your example, you seem to expect that the bits that are masked out will magically disappear. They don't. If you are ANDing two hex values, the masked bits become zero and are still there. You would need to perform other operations (i.e. right shifts) to extract and use the unmasked bits.

I'm guessing you would likely want to turn your value into an ASCII string and do some C string manipulation instead, but that's not my forte, so I could be wrong.
rnielsen



Joined: 23 Sep 2003
Posts: 852
Location: Utah

View user's profile Send private message

PostPosted: Wed Aug 16, 2006 2:22 pm     Reply with quote

Try using sprintf() to convert the number to a char (or rather a string) and then simply index through the characters, stuffing them where you want, and then convert the string back into an integer.

Ronald
rwyoung



Joined: 12 Nov 2003
Posts: 563
Location: Lawrence, KS USA

View user's profile Send private message Send e-mail

PostPosted: Wed Aug 16, 2006 2:25 pm     Reply with quote

Disable HTML when posting code, and continue to use the CODE button.

That said, the code you posted won't compile. The declaration is invalid, you can't have a space in a variable name and the number you are trying to initialize with is greater than 255, the largest 8-bit integer you can have. The default word size is 8-bits for the "int" data type in CCS.

From there it just gets worse. So I'm guessing the problem is your code posting got munged.
_________________
Rob Young
The Screw-Up Fairy may just visit you but he has crashed on my couch for the last month!
Display posts from previous:   
Post new topic   Reply to topic    CCS Forum Index -> General CCS C Discussion All times are GMT - 6 Hours
Page 1 of 1

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum


Powered by phpBB © 2001, 2005 phpBB Group