casevh wrote:
On Apr 28, 5:39 pm, Li Wang wrote:
2009/4/29 Tim Chase :
I want to concatenate two bits string together: say we have '1001' and
'111' which are represented in integer. I want to concatenate them to
'100' (also in integer form), my method is:
('1001' << 3) | 111
which
On Apr 28, 5:39 pm, Li Wang wrote:
> 2009/4/29 Tim Chase :
>
> >> I want to concatenate two bits string together: say we have '1001' and
> >> '111' which are represented in integer. I want to concatenate them to
> >> '100' (also in integer form), my method is:
> >> ('1001' << 3) | 111
> >> whi
On Wed, 29 Apr 2009 00:36:56 +1000, Li Wang wrote:
> Although bin(99)[4] could be used to locate it, this transform cost too
> much memory (99 only needs 2Bytes, while string '1100011' needs 7Bytes).
This is Python, not C. Your figures are completely wrong.
>>> sys.getsizeof(99)
12
>>> sys.getsi
2009/4/29 Tim Chase :
>>> You omit some key details -- namely how do you know that
>>> "1001" is 4 bits and not "1001" (8-bits)? If it's a
>>> string (as your current code shows), you can determine the
>>> length. However, if they are actually ints, your code should work fine &
>>> be O(1).
>
You omit some key details -- namely how do you know that
"1001" is 4 bits and not "1001" (8-bits)? If it's a
string (as your current code shows), you can determine the
length. However, if they are actually ints, your code
should work fine & be O(1).
Actually, what I have is a list of inte
2009/4/29 Tim Chase :
>> I want to concatenate two bits string together: say we have '1001' and
>> '111' which are represented in integer. I want to concatenate them to
>> '100' (also in integer form), my method is:
>> ('1001' << 3) | 111
>> which is very time consuming.
>
> You omit some key d
Li Wang wrote:
> 2009/4/29 Tim Chase :
>> Li Wang wrote:
>>> Hi:
>>>
>>> If I use an integer to represent bits:
>>> e.g. 99 represents '1100011'
>>>
>>> How can I locate, say the second bit of 99(i.e. '1')?
>>>
>>> Although bin(99)[4] could be used to locate it, this transform cost
>>> too much mem
I want to concatenate two bits string together: say we have '1001' and
'111' which are represented in integer. I want to concatenate them to
'100' (also in integer form), my method is:
('1001' << 3) | 111
which is very time consuming.
You omit some key details -- namely how do you know that
data = file('source.bin').read()
def get_bit(source, bit):
idx, bit = divmod(bit, 8)
byte = ord(source[len(source) - (1+idx)])
return (byte >> bit) & 1
My understanding is: when doing this step, every bit in the byte will
be shifted bit-long. If it is get_bit(data, 100), and the sourc
Li Wang wrote:
2009/4/29 Tim Chase :
Li Wang wrote:
If I use an integer to represent bits:
[snip]
Hummm, I have tried this method too, the problem is its time
complexity. If the length of my bits is n, then the time complexity is
O(n). When I tried to implement this in practice, it did consum
On 28 Apr, 17:24, Li Wang wrote:
> 2009/4/29 Tim Chase :
>
> > Li Wang wrote:
>
> >> Hi:
>
> >> If I use an integer to represent bits:
> >> e.g. 99 represents '1100011'
>
> >> How can I locate, say the second bit of 99(i.e. '1')?
>
> >> Although bin(99)[4] could be used to locate it, this transfor
2009/4/29 Tim Chase :
> Li Wang wrote:
>>
>> Hi:
>>
>> If I use an integer to represent bits:
>> e.g. 99 represents '1100011'
>>
>> How can I locate, say the second bit of 99(i.e. '1')?
>>
>> Although bin(99)[4] could be used to locate it, this transform cost
>> too much memory (99 only needs 2Byte
On 28 Apr, 16:36, Li Wang wrote:
> Hi:
>
> If I use an integer to represent bits:
> e.g. 99 represents '1100011'
>
> How can I locate, say the second bit of 99(i.e. '1')?
>
> Although bin(99)[4] could be used to locate it, this transform cost
> too much memory (99 only needs 2Bytes, while string '
Li Wang wrote:
Hi:
If I use an integer to represent bits:
e.g. 99 represents '1100011'
How can I locate, say the second bit of 99(i.e. '1')?
Although bin(99)[4] could be used to locate it, this transform cost
too much memory (99 only needs 2Bytes, while string '1100011' needs
7Bytes).
Anyone
Hi:
If I use an integer to represent bits:
e.g. 99 represents '1100011'
How can I locate, say the second bit of 99(i.e. '1')?
Although bin(99)[4] could be used to locate it, this transform cost
too much memory (99 only needs 2Bytes, while string '1100011' needs
7Bytes).
Anyone knows how to loca
15 matches
Mail list logo