473,756 Members | 4,511 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

What's happended to ANSI chars 135 and 130 - ToString/GetBytes

Hi,

Here's a little hack I put together to try to get to the bottom of a
problem I'm having with trying to base64 encode a hash value. The hash
value contains character codes 135 and 130 amongst others.

This snippet will set up a string of chars 190, 135, 130, 73, 242, 243,
10. It puts them into a bytearray.

string encodedData;
byte[] andBackAgainByt es;
char a1 = (char)190;
char a2 = (char)135;
char a3 = (char)130;
char a4 = (char)73;
char a5 = (char)242;
char a6 = (char)243;
char a7 = (char)10;
string data = a1.ToString() + a2.ToString() + a3.ToString() +
a4.ToString() + a5.ToString() + a6.ToString() + a7.ToString();
byte[] encData_byte = new byte[data.Length];
encData_byte = System.Text.Enc oding.Default.G etBytes(data);

However when debugging I look at the resulting byte array I see the
following character codes:

190, 63, 63, 73, 242, 243, 10

Note: the ANSI character "single baseline quote" is char 130 and
"dagger (double)" is char 135.

Any idea what happended to chars 130 and 135. I know a work around but
I'm curious as to why this is the case.

Thanks
Gizmo

May 31 '06 #1
2 3728

gizmo wrote:
Hi,

Here's a little hack I put together to try to get to the bottom of a
problem I'm having with trying to base64 encode a hash value.
The quick answer is to use Convert.ToBase6 4String on a byte array, but
we will continue for the purposes of enlightenment :)
The hash
value contains character codes 135 and 130 amongst others.
Contains *bytes* 135 and 130. One of the key things about thinking C#
rather than C/++ is knowing that "bytes is bytes and characters is
characters, and only via an Encoding shall the twain meet".

This snippet will set up a string of chars 190, 135, 130, 73, 242, 243,
10.
We'll see what it does in just a moment
It puts them into a bytearray.

string encodedData;
byte[] andBackAgainByt es;
char a1 = (char)190;
char a2 = (char)135;
char a3 = (char)130;
char a4 = (char)73;
char a5 = (char)242;
char a6 = (char)243;
char a7 = (char)10;
OK so far, though semantically dodgy...
string data = a1.ToString() + a2.ToString() + a3.ToString() +
a4.ToString() + a5.ToString() + a6.ToString() + a7.ToString();
Still fine, chars can become strings just fine...
byte[] encData_byte = new byte[data.Length];
encData_byte = System.Text.Enc oding.Default.G etBytes(data);
And here's the problem. Now, your IP is (like me) in the UK, so I'm
going to guess that your default encoding is the same as mine - good
old Windows Codepage 1252, which is like but not the same as)
iso-8859-1. Now, there's a funny thing about this encoding. Take a look
at <http://en.wikipedia.or g/wiki/ISO/IEC_8859-1#Code_table> - and
you'll see a big gap in the middle marked 'unused'. Further down, we
are told "Code values 00-1F, 7F, and 80-9F are not assigned to
characters by ISO/IEC 8859-1". This is our problem - the characters
represented by (char)130 (0x82) and (char)135 (0x87) simply *are not
present* in Encoding.Defaul t, so cannot be converted by it into bytes.
However when debugging I look at the resulting byte array I see the
following character codes:

190, 63, 63, 73, 242, 243, 10
So it helpfully gives us ?s instead - which is where the 63s come from.

Note: the ANSI character "single baseline quote" is char 130 and
"dagger (double)" is char 135.

Any idea what happended to chars 130 and 135. I know a work around but
I'm curious as to why this is the case.


Hopefully I have slightly cleared up the why, but the really important
thing is to get the concept of the separation between characters and
bytes completely embedded in the way you think C#.

--
Larry Lard
Replies to group please

May 31 '06 #2
dmm
I think the problem is that you are mixing your codepages. Casting an
integer value to a char will invoke the unicode codepage (.NET chars are 2
byte unicode chars). You are then using
the Windows 1252 codepage to try to get back to the origonal value.

"gizmo" <ga*********@gm ail.com> wrote in message
news:11******** **************@ c74g2000cwc.goo glegroups.com.. .
Hi,

Here's a little hack I put together to try to get to the bottom of a
problem I'm having with trying to base64 encode a hash value. The hash
value contains character codes 135 and 130 amongst others.

This snippet will set up a string of chars 190, 135, 130, 73, 242, 243,
10. It puts them into a bytearray.

string encodedData;
byte[] andBackAgainByt es;
char a1 = (char)190;
char a2 = (char)135;
char a3 = (char)130;
char a4 = (char)73;
char a5 = (char)242;
char a6 = (char)243;
char a7 = (char)10;
string data = a1.ToString() + a2.ToString() + a3.ToString() +
a4.ToString() + a5.ToString() + a6.ToString() + a7.ToString();
byte[] encData_byte = new byte[data.Length];
encData_byte = System.Text.Enc oding.Default.G etBytes(data);

However when debugging I look at the resulting byte array I see the
following character codes:

190, 63, 63, 73, 242, 243, 10

Note: the ANSI character "single baseline quote" is char 130 and
"dagger (double)" is char 135.

Any idea what happended to chars 130 and 135. I know a work around but
I'm curious as to why this is the case.

Thanks
Gizmo

May 31 '06 #3

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

Similar topics

24
2411
by: Xah Lee | last post by:
in computer languages, often a function definition looks like this: subroutine f (x1, x2, ...) { variables ... do this or that } in advanced languages such as LISP family, it is not uncommon to define functions inside a function. For example:
13
6140
by: Dan V. | last post by:
How do I create a one line text file with these control codes? e.g.: 144 = 0x90 and 147 = 0x93? I am trying to create a one line text file with these characters all one one row with no spaces. 1. 144 = 0x90 2. 147 = 0x93 3. STX = (^B = 2 = 0x2) 4. NUL = (^@ = 0 = 0x0)
20
4174
by: Drebin | last post by:
It's a long story really, but the bottom line is we need to encrypt or obfuscate a clear-text 9-digit SSN/taxpayer ID into something less than 21 characters. It doesn't need to be super-secure, just something that isn't plain-text and it HAS to be as unique as the original number. It also does not need to be a symmetric algorithm - we are using this as a way to create a unique "userid" on a system to which we single-signon. So it's used...
4
79655
by: Julia | last post by:
Hi, I need to convert unicode string to ansi string Thanks in adavance.
2
13922
by: Clay | last post by:
I need to convert a unicode string to an ansi string. This should not be difficult but I simply cannot find a way to do this. Anyone?
1
1278
by: intrader | last post by:
I have a .NET interop assembly Hash.MD5Sum with two methods Identity and GetMD5Sum. I want to call the methods from ASP (JScript), The debugger tells me that object oMD5Sum has one the ToString() method. How do I get the Identity and GetMD5Sum methods to be accessible? I include the entire .net assembley followed by a snippet of the ASP code. /////The code of the .NET assembly is: using System;
6
18052
by: msdnuniv | last post by:
Hello everybody, since days i try to convert Unicode-Strings in VB.NET to ANSI which should be processable in VB6 and converted to unicode again. It should be possible with any codepage, e.g. somebody on a greek PC should be able to handle chinese strings -------------- VB.NET ---------------- 'On the vb.net side (I am pretty sure, it is correct(?)) Dim oEncoderAnsi As System.Text.Encoding
3
6923
by: Pascal | last post by:
Hello can someone help please ? here is the code in vb6 Dim lChar As Integer lChar =AscB(Mid(sMessage, lByteCount + 1, 1)) i tried lChar = System.Convert.ToUInt16(Asc(Mid(sMessage, lByteCount + 1, 1))) Mod 256
3
2859
by: =?iso-8859-1?B?S2VyZW0gR/xtcvxrY/w=?= | last post by:
Hi, i have a byte that holds a bunch of data of type REG_MULTI_SZ in UNICODE,. I must convert this byte to a REG_MULTI_SZ in ANSI code. How can i do this,...? TIA,... Regards
0
9271
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 effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
9869
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 tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
1
9838
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
9708
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 protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
1
7242
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 presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
6534
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
5302
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
3805
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
2
3354
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

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.