473,404 Members | 2,137 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,404 software developers and data experts.

base64 encode characters > 127

I seem to be having a problem base64 encoding characters above 127. I
can encode a sentence like "The big bad dog" without problems, but if
I try to encode something like 0xFF I get different results than in
Perl.

For example I am using:

byte[] binaryArray =
System.Text.ASCIIEncoding.ASCII.GetBytes(binaryStr ing);
string pushString = System.Convert.ToBase64String(binaryArray);
MessageBox.Show(pushString);

For 0xFF I get the result: Pw== which doesn't match my results in
Perl.

If it helps, I am converting a HEX input from a string, like FFE0 etc
with the following:

for (int i=0;i<hexString.Length;i=i+2)
{
string tmpstr = (((char)hexString[i]).ToString()+((char)hexString
[i+1]).ToString());
int hex = Convert.ToInt32(tmpstr,16);
binaryString += (char)hex;
}

I run into problems with ASCII.GetBytes()

It seems it takes my 255 for FF and turns it into 127

If I use Unicode instead I get 255, but it uses two spots in the byte
array, like

255 0

Essentially I need FFFFFFFF as an input to turn into a byte array of:

255 255 255 255 255 255 255 255

Any ideas?

Thanks,

Curt
Nov 15 '05 #1
1 2958
Curt Fluegel <cu**@thewebpractice.com> wrote:
Essentially I need FFFFFFFF as an input to turn into a byte array of:

255 255 255 255 255 255 255 255

Any ideas?


Yes - you're talking about *binary* data here, so don't try to treat it
as *character* data.

Create a byte array which is of an appropriate size, then populate it
by taking each pair of characters in turn and using Byte.Parse with the
number style of HexNumber.

--
Jon Skeet - <sk***@pobox.com>
http://www.pobox.com/~skeet
If replying to the group, please do not mail me too
Nov 15 '05 #2

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

Similar topics

0
by: Ramy076 | last post by:
I have a C App which uses openssl for Encoding and decoding which needs to be ported to java. The decoded text does not match between the C App and the java App. The size of the output itself is...
3
by: wenmang | last post by:
Hi, I ma thinking whether to use Base64 encoding to encode the binary content in the XML file. I have done some simple calculations, it seems to me that the size for encoded content increases by...
4
by: John | last post by:
Hi all, I've been going through google and yahoo looking for a certain base64 decoder in C without success. What I'm after is something that you can pass a base64 encoded string into and get back...
4
by: Curt Fluegel | last post by:
I seem to be having a problem base64 encoding characters above 127. I can encode a sentence like "The big bad dog" without problems, but if I try to encode something like 0xFF I get different...
3
by: nly | last post by:
What's the purpose of "Base64 encoding and decoding"? Thanks in advance!
4
by: Simon Pulo | last post by:
Hello I've managed to encode an image file to base64 using "convert.ToBase64String" I know you cannot send the whole string to the server, but you need to send so many char's at a time which i...
5
by: Jay | last post by:
I have bean trying to get my head around reading .GIF files from base64 strings, Basically I need to specify a filename and convert it to base64 then I can copy/past the string to wear I want it....
13
by: aruna.eies.eng | last post by:
i am currently trying to convert data into binary data.for that i need to know how to achieve it in c language and what are the libraries that we can use. so if any one can send me a sample code or...
4
by: Clodoaldo | last post by:
I'm using a md5 hash encoded with base64.urlsafe_b64encode as a parameter of a URL used to confirm a registration in a site. It has been working great. The url is like this: ...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
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: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
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,...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...

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.