-3

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

Grace Note
  • 3,205
  • 4
  • 35
  • 55
user46646
  • 153,461
  • 44
  • 78
  • 84

2 Answers2

2

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
  • 316,276
  • 54
  • 369
  • 333
0

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
  • 5,584
  • 4
  • 35
  • 47