If you must do this, use an unsigned int. There is already a Base64 utility
in System.Convert that does what you want. However, if, for your own
reasons, you need or want to do it you way still, look at my bit manipulator
class that may help you, search for "Shawn Bullock" on
www.planet-source-code.com in the .net section and you'll see a bitwise
value type in C# (not vb compatible). It overloads all the operators and
allows you to work with a value just like you do an int, but it help you a
little with bit manipulations.
Of course, you can also do this in C# (I strongly recommend using an
unsigned int or UInt32) just use the << and >> operators to shift and to or
them together use the | character.
For example,
A |= B
In the bitwise class I wrote, you can say
Binary32 a = "1100";
Binary32 b = "0001";
a |= b; // := "1101"
Of course, you'll get the same results with an unsigned int like this:
uint a = 12;
uint b = 1;
a |= b;
Etc, Etc, Etc.
The only thing the Binary class I wrote does that you can't do automatically
with a standard valuetype is rotate left or rotate rigth, and get/set
individual bits. For example,
Binary8 x = "11011101";
if (x[1] == true || x[2] == 1 || x[5] == "0") {
...
}
Binary8 y = "11011101";
y[3] = 1; // "11011111";
But there are other ways of going about getting the same information with a
uint.
I wrote that class because I wrote a 6502 processor simulator in C# and
needed these kinds of bit operations. It's fast, too. You get the source
code.
As it pertains to your original question, if you look at the source code,
you'll get a lot of insight into doing the kinds of bit manipulations you
desire for your own work in question.
Thanks,
Shawn
<Mike> wrote in message news:ua**************@TK2MSFTNGP11.phx.gbl...
I am woking on a base64 encoder and I am looking for some design help. I
have a woking model but would like some input on the design. I currently
read 3 bytes from a binary stream with each byte place in a seperate int32
var. Bytes are shifted to the left 0 8 or 16 places then the 3 vars are
"or"ed together t make a stream of bits. I then extract each 6 bit set
using a mask into a new int32 then shift them to the right to the fist
byte position. This seems to work OK but I am looking for other ideas to
implment this functionality.