![]() |
String of bits to byte[]
how can i convert a string of bit String S = "01010101010101010101"
into a byte b[] dont worry about left over bits.. assume that the size of S is a multiple of 8-bits |
Re: String of bits to byte[]
Start with a byte of 0. Traverse each character from left to right, shifting the byte left with
<< 1. Each time you encounter a bit that's 1, set the first bit with | 1.Do this for each grouping of 8 bits to get your byte[]. For example, given the string "01010101010101010101": :
Byte Operation String During Iteration |
| All times are GMT -5. The time now is 12:53 AM. |
Powered by vBulletin® Version 3.7.0, Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
Copyright ©2007 DaniWeb® LLC