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

make a byte between 2 other bytes

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



Joined: 21 Feb 2004
Posts: 12
Location: Santiago - Chile

View user's profile Send private message

make a byte between 2 other bytes
PostPosted: Thu Mar 04, 2004 2:37 pm     Reply with quote

Hi.

i need to create a byte, but from the half of other 2 bytes.

This is for implementig a FAT12 routine, FAt 12 mean that it use only 12 bits. Then i will write this on a Compact Flash.

Well, now i have a counter to a max number of 4095= FFFh. And i need to make this composition using 3 bytes = 24 bits then dividing the byte in the half between the numbers.

Its better an example i think.

Example: For implementing the 12 bits, i have to produce this numbers --> 001 002 003.... FFD FFE FFF; and my problem es because i can only write bytes blocks to save into the compact flash 00 10 02 00 3X XX........XX XF FD FF EF FF

So, now i'm "cuting & paste" the XXX numbers into a XXh XXh but i can't know how to do that.

Now i'm Using this algorithm, but don't know....

notice this --> unsigned long int k; k++
1) write (k>>8))
2) write (k+1)>>4 & 0xFF) & (k<<4 & 0xFF)
3) write (k+1 & 0xFF))
4)k++

ONE QUESTION:
The "& " is for paste the bytes?

I'm very lost with this..:-(
Neutone



Joined: 08 Sep 2003
Posts: 839
Location: Houston

View user's profile Send private message

PostPosted: Thu Mar 04, 2004 3:05 pm     Reply with quote

If I understand correctly you wish to store 12 bit words in sets using 3 bytes per set. I would use a byte for the lower half of each word and use the remaining byte to store the upper nibbles.

word_1 = ((Byte3&0x0F)<<8) + Byte1;
word_2 = (((swap(Byte3))&0x0F)<<8) + Byte2;
SteveS



Joined: 27 Oct 2003
Posts: 126

View user's profile Send private message

PostPosted: Thu Mar 04, 2004 3:14 pm     Reply with quote

Not sure I understand exactly, but let me try an answer:

First:
'&' is a bit-wise AND operator - it will produce a result that has a '1' in each bit location only if both inputs have a '1' at that location, so (in binary)

0101 & 0011 = 0001

'|' (vertical bar) is the bit-wise OR operator - it produces a '1' in the result
each bit of the result if either input has a '1' at that bit:

0101 | 0011 = 0111

That may be the 'paste' operation you are thinking of.

Ok, now if you want to turn (hex now) 001 002 003 ... into 00 10 02 00 3...
I think you have the right idea, but a couple corrections

1) write (k>>4)) // not >> 8 to get rid of the lower 4 bits
2) write (k+1)>>4 & 0xFF) | (k<<4 & 0xFF) // | not & to combine the pieces
3) write (k+1 & 0xFF)) // ok
4)k += 2; // since each loop actually takes care of two 12 bit values.

SteveS
iseron



Joined: 21 Feb 2004
Posts: 12
Location: Santiago - Chile

View user's profile Send private message

PostPosted: Sat Mar 06, 2004 10:33 pm     Reply with quote

Thanks!!

Excelent Guide to finish this part of my algorithm.

The given code was not exactly what was i looked for but. i learn it!

Really thanks!

Ignacio.
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