decoding

Decoding an UTF-8 string to Windows-1256

試著忘記壹切 提交于 2019-12-23 19:45:48
问题 I used this code to encode a UTF-8 string to Windows-1256 string: string q = textBox1.Text; UTF7Encoding utf = new UTF7Encoding(); byte[] winByte = Encoding.GetEncoding(1256).GetBytes(q); string result = utf.GetString(winByte); This code is working but I can't decode the result or encoded to original string! How I can decode an encoded string (result variable) to same before converted (q variable)? 回答1: You are converting the strings incorrectly. Have a look at the commented code below. The

EncodeError with \xa3 (pound sign)

与世无争的帅哥 提交于 2019-12-23 01:21:11
问题 I'm trying to get some data from a web page. This webpage has stated that charset is utf-8. But there is a problem with \xa3 sign. I can't be encoded or decoded into/from 'utf-8'. for key,value in self.__dict__.iteritems(): if key not in self.db_attributes: print repr(value) attrs_statement+=str(key)+', ' values_statement+=str(value)+', ' ERROR: u'\xa3410' Traceback (most recent call last): File "C:\Users\Milano\My Documents\LiClipse Workspace\Velvet_scraper\vehicle.py", line 432, in <module>

convert 16 bit grayscale DICOM image to 8 bit: the correct procedure

房东的猫 提交于 2019-12-22 11:08:43
问题 I have been trying to create an image viewer for DICOM image. My program reads all the 8 bit colour and grayscale image almost correctly. But when I try to open a 16 bit image using the first 8 bits of the image, some parts are missing (pixels which uses 16 bit will be shown as dark instead of whilte). I don't really know how to use the window centre, window width, rescale slop and intercept. Please help me by giving the exact steps to convert 16 bit image to 8 bit image. Also I don't need to

Why are the lengths different when converting a byte array to a String and then back to a byte array?

会有一股神秘感。 提交于 2019-12-22 08:49:04
问题 I have the following Java code: byte[] signatureBytes = getSignature(); String signatureString = new String(signatureBytes, "UTF8"); byte[] signatureStringBytes = signatureString.getBytes("UTF8"); System.out.println(signatureBytes.length == signatureStringBytes.length); // prints false Q: I'm probably misunderstanding this, but I thought that new String(byte[] bytes, String charset) and String.getBytes(charset) are inverse operations? Q: As a follow up, what is a safe way to transport a byte[

Base64 Encoding: Illegal base64 character 3c

孤人 提交于 2019-12-22 08:00:09
问题 I am trying to decode data in an xml format into bytes base64 and I am having an issues. My method is in java which takes a String data and converts it into bytes like as bellow. String data = "......"; //string of data in xml format byte[] dataBytes = Base64.getDecoder().decode(data); Which failed and gave the exception like bellow. java.lang.IllegalArgumentException: Illegal base64 character 3c at java.util.Base64$Decoder.decode0(Base64.java:714) at java.util.Base64$Decoder.decode(Base64

Java URLDecoder throws exception when used with a string containing a %

烈酒焚心 提交于 2019-12-22 05:04:07
问题 I have a problem with the URLDecoder of Java. I am escaping a String in JavaScript, and send it to a java servlet. Then I decode the escaped String with the following line: URLDecoder.decode(request.getParameter("text"), "UTF-8"); This works fine for every special characters I have tried, the only one making problems is the '%'. Everytime I use this character in the string, I get the following exception: java.lang.IllegalArgumentException: URLDecoder: Incomplete trailing escape (%) pattern

Java URLDecoder throws exception when used with a string containing a %

China☆狼群 提交于 2019-12-22 05:04:03
问题 I have a problem with the URLDecoder of Java. I am escaping a String in JavaScript, and send it to a java servlet. Then I decode the escaped String with the following line: URLDecoder.decode(request.getParameter("text"), "UTF-8"); This works fine for every special characters I have tried, the only one making problems is the '%'. Everytime I use this character in the string, I get the following exception: java.lang.IllegalArgumentException: URLDecoder: Incomplete trailing escape (%) pattern

TypeError: decoding str is not supported

南楼画角 提交于 2019-12-22 04:06:28
问题 Im trying to make a attribute characteristic randomiser for my nephews board game and I'm trying to write the attributes to an external file so that he can use them later. when i am trying to write to the file it comes up with the error speedE = str('Speed -', str(speed)) TypeError: decoding str is not supported my code is adding the calculated attribute to the name of the attribute. I.E. ('Strength - ', strengthE) my code is ... import random char1 = open('Character1.txt', 'w') strength = 10

Convert binary files into ascii in Python

穿精又带淫゛_ 提交于 2019-12-22 00:08:27
问题 I have a bunch of binary files that contain data in the following format: i\xffhh\xffhh\xffhh\xffih\xffhh\xffhh\xffhh\xffhh\xffhi\xffii\xffjj\xffjj\xffjj\xffjk\xffkk\xffkk\xffkl\xffll\xffmm\xffmn\xffnn\xffon\xffno\xffop\xffop\xffpp\xffqq\xffrq\xffrs\xffst\xfftt\xfftt\xffuv\xffvu\xffuv\xffvv\xffvw\xffwx\xffwx\xffxy\xffyy\xffyz\xffz{\xffz{\xff||\xff}|\xff~}\xff}}\xff~~\xff~~\xff~\x7f\xff\x7f\x7f\xff\x7f\x7f\xff\x7f\x7f\xff\x80\x80\xff\x80\x81\xff\x81\x80\xff\x81\x81\xff\x81\x82\xff\x82\x82\xff

Decoding tcp packets using python

筅森魡賤 提交于 2019-12-21 23:59:28
问题 I am trying to decode data received over a tcp connection. The packets are small, no more than 100 bytes. However when there is a lot of them I receive some of the the packets joined together. Is there a way to prevent this. I am using python I have tried to separate the packets, my source is below. The packets start with STX byte and end with ETX bytes, the byte following the STX is the packet length, (packet lengths less than 5 are invalid) the checksum is the last bytes before the ETX def