Re: bits question

  • From: "Tyler Littlefield" <tyler@xxxxxxxxxxxxx>
  • To: <programmingblind@xxxxxxxxxxxxx>
  • Date: Sat, 11 Apr 2009 11:59:41 -0600

awesome, thanks.
I'm playing around with the emulator, and was working on getting background 
color set up.
so, I have bits 9-12, so I could do something like:
short i;
i<<8=(char)65;
i|=0xf<<12;
which would set the low nibble of the high byte to 0xf. (I think)...


Thanks,
Tyler Littlefield
Web: tysdomain.com
email: tyler@xxxxxxxxxxxxx
My programs don't have bugs, they're called randomly added features.

  ----- Original Message ----- 
  From: tribble 
  To: programmingblind@xxxxxxxxxxxxx 
  Sent: Saturday, April 11, 2009 11:53 AM
  Subject: Re: bits question


  Hi Tyler --
    Sounds like what you need is shift and bitwise operations on the word. 
Suppose wd is the word. To get to the upper 4 bits, shift left  and use bitwise 
ops as follows:
    If 15-12 is the nibble you are using, and if x has the bit pattern you want 
in the top nibble,

    wd   |= (x<<12);

    This will set all the bits that are set in x, and leave the other bits as 
they were in wd.

    To clear bits specified in x, do this:

    wd &= ~(x<<12);


    To completely clear the nibblein wd , just do

    wd &=~(0xF<<12);

    HTH -- just play around and it will become easier.
    --le




    ----- Original Message ----- 
    From: Tyler Littlefield 
    To: programmingblind@xxxxxxxxxxxxx 
    Sent: Saturday, April 11, 2009 10:54 AM
    Subject: bits question


    Hello list,
    I've got a quick question.
    I have a short, (16 bits) and need to set the upper 8 bits.
    I have 1-F which I need to use, and I need to set them in nibbles.
    so it'd look something like
    0x00F1
    or what ever I used for the last bit. any ideas on how to do this would be 
great.



    Thanks,
    Tyler Littlefield
    Web: tysdomain.com
    email: tyler@xxxxxxxxxxxxx
    My programs don't have bugs, they're called randomly added features.

Other related posts: