473,396 Members | 1,875 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,396 software developers and data experts.

Bit Encoding design

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.
Nov 20 '05 #1
2 1349
On 2004-02-03, <Mike> <> wrote:
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.


Is there some reason not to use the functionality built into the
framework?

System.Convert.ToBase64String
System.Convert.FromBase64String
System.Convert.ToBase64CharArray
System.Convert.FromBase64CharArray

Just curious....

--
Tom Shelton [MVP]
Powered By Gentoo Linux 1.4
There are two major products that come out of Berkeley: LSD and UNIX.
We don't believe this to be a coincidence.
-- Jeremy S. Anderson
Nov 20 '05 #2
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.

Nov 20 '05 #3

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

3
by: Jon Davis | last post by:
I have a software application I've written called PowerBlog (PowerBlog.net) that takes the editing capability of the Internet Explorer WebBrowser control (essentially a DHTMLTextBox), extracts the...
0
by: Grey | last post by:
I am gonna to design a web application with differnet word encoding format. I have english, traditional chinese and simplified chinese in the ASP.NET web application. When i use some simplified...
5
by: James Wong | last post by:
Dear all, I've a web service function and it contains a parameter in System.Text.Encoding. I found that the data type of this parameter in caller application becomes MyWebSvcName.Encoding...
1
by: Untitled | last post by:
I currently have a web application with hundreds of pages and controls. There currently is no HTML Encoding done anywhere. Data to the application come from all different places such as UI,...
12
by: Christian Roth | last post by:
Hello, I am merely asking this for my own understanding: Processing instruction's data part is not entity-aware, i.e. character and numercial entities are not resolved at parsing time. E.g., ...
4
by: Bob | last post by:
Hi Need to produce a Doc with no encoding info. Is there anyway of doing this? Thanks Bob i.e. <?xml version=\"1.0\" ?>
1
by: Boki | last post by:
Hi All, Here is the code: Shell("D:\Program Files\Mozilla Firefox\firefox.exe http://tw.dictionary.yahoo.com/search?ei=UTF-8&p=" & TextBox1.Text) If I type English word in TextBox1, I can...
5
by: Licheng Fang | last post by:
I want to store Chinese in Unicode internally in my program, and give output in UTF-8 or GBK format. After two days of searching and reading, I still cannot find a simple and straightforward way to...
19
by: Edward K. Ream | last post by:
Following the usual cookbook examples, my app parses an open file as follows:: parser = xml.sax.make_parser() parser.setFeature(xml.sax.handler.feature_external_ges,1) # Hopefully the...
4
by: harrelson | last post by:
I have a large amount of data in a postgresql database with the encoding of SQL_ASCII. Most recent data is UTF-8 but data from several years ago could be of some unknown other data type. Being...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.