By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
425,979 Members | 943 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 425,979 IT Pros & Developers. It's quick & easy.

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

P: n/a

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(000000111111 111000111111). if
it needs to expanded by 4 times then(0000000011111111
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
Mar 23 '08 #1
Share this Question
Share on Google+
2 Replies


P: n/a
On Sat, 22 Mar 2008 22:32:03 -0700 (PDT), hari <ha********@gmail.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(000000111111 111000111111). if
it needs to expanded by 4 times then(0000000011111111
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.
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
Mar 23 '08 #2

P: n/a

"hari" <ha********@gmail.comwrote in message
news:dc**********************************@d4g2000p rg.googlegroups.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(000000111111 111000111111). if
it needs to expanded by 4 times then(0000000011111111
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,int,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;

}

Mar 23 '08 #3

This discussion thread is closed

Replies have been disabled for this discussion.