Thanks, I was looking for this. Stefano Jan van Wijk ha scritto: > Hello Stefano, > > On Fri, 30 Jan 2009 08:48:31 +0100, Stefano Vanzo wrote: > >>>> With 16bit models can I do: >>>> >>>> DATA_PORT |= data8bit & 0x00f0; > > Yes, allthough I do not understand why you 'and' with 0x00f0. > That will ZERO the four lowest bits from your data8bit value. > But that is probably part of yor application logic :-) > > >>>> or do I have to: >>>> >>>> int data16bit = 0x0000; >>>> data16bit += data8bit; >>>> DATA_PORT |= data16bit & 0x00f0; > > No, that has the same effect as the above ... > The 8-bit value is automatically promoted to 16 bit. > >>>> The question: can I "and" a char with a int ending up with the char in >>>> the first two nibbles? > > Yes > > >> I have two 16bits because DATA_PORT is 16 bit. I want to know if >> data8bit ends up in the lowwer part of DATA_PORT and does not effect the >> two high nibbles. > > Well, it DOES affect the high nibbles in principle, but since your operation > is an OR, and the two high-nibbles in your argument are ZERO, no change > will take place. (the |= causes a 16-bit read-modify-write) > > Your 8-bit value is promoted to a 16-bit value before that operation, > in this case by adding two zero nibbles. >> DATA_PORT |= data8bit & 0x00f0; > > For readability, I would add parentheses on the 'and' clause: > > DATA_PORT |= (data8bit & 0x00f0); > > Regards, JvW > > Jan van Wijk, author of DFSee; http://www.dfsee.com > ------------------------------------------------------------------------------- -- http://www.piclist.com PIC/SX FAQ & list archive View/change your membership options at http://mailman.mit.edu/mailman/listinfo/piclist