views:

209

answers:

2

I want to convert strings to bit-fields.Also,convert them to binary and then use. Need help with this..help me ..

A: 

they're all binary already... Which language are we talking about?

I'd start by looking at the string as an array of characters and working with each character individually.

Cogsy
@Cogsy - Language is Python. Question not really sensible.
S.Lott
+2  A: 

I think the struct module is what you're after.

Example of usage:

>>> from struct import *
>>> pack('hhl', 1, 2, 3)
'\x00\x01\x00\x02\x00\x00\x00\x03'
>>> unpack('hhl', '\x00\x01\x00\x02\x00\x00\x00\x03')
(1, 2, 3)
>>> calcsize('hhl')
8
Greg