Bit expansion by 2times,3times....10 times

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • hari

    #1

    Bit expansion by 2times,3times....10 times


    Hi all,

    suppose a hex value is there(say 3B), this needs to be expanded.

    Suppose if this 3B(0011 1011) needs to be expanded by 3 times, then
    each bit should be expanded by 3 times(000000111 111 111000111111). if
    it needs to expanded by 4 times then(0000000011 111111
    111100001111111 ).hpow can I do this.I m tring to do this,but :(. I
    need to do this expansion 10 times)

    any suggestion will be great help.same query I have posted as
    converting nibble to bytes and bytes to nibble,But I feel on expanding
    by 3 times I m getting in to problems.

    Regards
    Hari
  • Barry Schwarz

    #2
    Re: Bit expansion by 2times,3times.. ..10 times

    On Sat, 22 Mar 2008 22:32:03 -0700 (PDT), hari <haricibi83@gma il.com>
    wrote:
    >
    >Hi all,
    >
    >suppose a hex value is there(say 3B), this needs to be expanded.
    >
    >Suppose if this 3B(0011 1011) needs to be expanded by 3 times, then
    >each bit should be expanded by 3 times(000000111 111 111000111111). if
    >it needs to expanded by 4 times then(0000000011 111111
    >11110000111111 1).hpow can I do this.I m tring to do this,but :(. I
    >need to do this expansion 10 times)
    >
    >any suggestion will be great help.same query I have posted as
    >converting nibble to bytes and bytes to nibble,But I feel on expanding
    >by 3 times I m getting in to problems.
    >
    The answers you received to your similar request four days ago are
    equally applicable. If you didn't save them, you can probably find
    them on google. Show us what you have done so far.


    Remove del for email

    Comment

    • Bartc

      #3
      Re: Bit expansion by 2times,3times.. ..10 times


      "hari" <haricibi83@gma il.comwrote in message
      news:dcf740e0-1942-487e-a0e5-fd18ed063a6f@d4 g2000prg.google groups.com...
      >
      Hi all,
      >
      suppose a hex value is there(say 3B), this needs to be expanded.
      >
      Suppose if this 3B(0011 1011) needs to be expanded by 3 times, then
      each bit should be expanded by 3 times(000000111 111 111000111111). if
      it needs to expanded by 4 times then(0000000011 111111
      111100001111111 ).hpow can I do this.I m tring to do this,but :(. I
      need to do this expansion 10 times)
      >
      any suggestion will be great help.same query I have posted as
      converting nibble to bytes and bytes to nibble,But I feel on expanding
      by 3 times I m getting in to problems.
      What's the problem with doing it 10 times?

      The following code duplicates bits in an integer value.

      If this sort of code is no good then you must be more specific in your
      requirements.

      You mentioned something about printing in a previous post, sounded like
      bit-image scaling. That doesn't sound difficult: to scale by 3 times,
      duplicate each byte by 3 (as below), send the low 24-bits of the duplicated
      value. And repeat to end of row. Then do the same thing for the next two
      rows.

      Bart


      #include <stdio.h>

      int duplbits(int,in t,int);

      int main(void)
      {int x,y;

      x=0x31;

      y=duplbits(x,8, 4);

      //printf("x = %B\n",x);
      //printf("y = %B\n",y);

      printf("x = %X\n",x);
      printf("y = %X\n",y);


      }

      /*duplicate least-significant <bitsof a, n times, return result */

      int duplbits(int a,int bits,int n)
      {
      int b,amask,bmask;
      int i;
      int count;

      if (bits<=0 || n<=0) return 0;

      amask=1;
      bmask=1;

      b=0;

      for (i=1; i<=bits; ++i)
      {
      count=n;
      do
      { if (a & amask)
      b |= (~0 & bmask);
      bmask <<= 1;
      }
      while (--count);

      amask <<= 1;
      };

      return b;

      }



      Comment

      Working...