PDA

View Full Version : String to bytes



giannissam
04-06-2009, 02:54 AM
Hello, i've been trying to convert a string to bytes in this way
say the string is "jj"
in binary its
01101010 01101010

i want to make

00000000 00000000
10000000 10000000
10000000 10000000
00000000 00000000
10000000 10000000
00000000 00000000
10000000 10000000
00000000 00000000

i made a code (attached) but somehow when it gets to the second j the bin is diferent. (By the way in my code i havent masked the bin numbers so i can see the process)

StefanL38
04-06-2009, 05:25 AM
Hello Giannissam,

from a quick look at your code I guess the memoryarea of




EncBit byte '" ",0




is too small as it contains only ONE byte

how about




EncBit byte 0,0,0,0,0,0,0,0
byte 0,0,0,0,0,0,0,0
byte 0,0,0,0,0,0,0,0
byte 0,0,0,0,0,0,0,0




to have a memory area of 32 bytes ?

Your encoding is compressed as much as possible
how about decompressing it for testpurposes

I mean one line of code for
checking if bit is 0 or 1
another line for setting msb
another line for increment the pointer
another line for shifting the bits ONE bit left etc.
and if this works properly starting to compress it

best regards

Stefan

giannissam
04-07-2009, 10:09 AM
actually i wanted to make lsb not msb. but anyway u helped a lot. thanx