byte

Swift Bit array to Bytes array (UInt8 array)

半城伤御伤魂 提交于 2019-12-30 06:46:21
问题 I have array with bits: var bits: [Bit] and how could I convert it to bytes array: var bytes: [UInt8] For example I have 280 bits and I should have 35 UInt8 in bytes array. I can think of solution where I take 8bits and check if first is true, if second is true and so and sum the results and have value. This I would do for every 8bits in my bits array. But I think this would be bad solution (it would work but with unnecessary calculations). I think there could be faster solution with some

Swift Bit array to Bytes array (UInt8 array)

…衆ロ難τιáo~ 提交于 2019-12-30 06:45:52
问题 I have array with bits: var bits: [Bit] and how could I convert it to bytes array: var bytes: [UInt8] For example I have 280 bits and I should have 35 UInt8 in bytes array. I can think of solution where I take 8bits and check if first is true, if second is true and so and sum the results and have value. This I would do for every 8bits in my bits array. But I think this would be bad solution (it would work but with unnecessary calculations). I think there could be faster solution with some

why doesn't byte[] to string and back work as expected

倖福魔咒の 提交于 2019-12-30 06:34:49
问题 I have this code: Int32 i1 = 14000000; byte[] b = BitConverter.GetBytes(i1); string s = System.Text.Encoding.UTF8.GetString(b); byte[] b2 = System.Text.Encoding.UTF8.GetBytes(s); Int32 i2 = BitConverter.ToInt32(b2,0);; i2 is equal to -272777233. Why isn't it the input value? (14000000) ? EDIT: what I am trying to do is append it to another string which I'm then writing to file using WriteAllText 回答1: Because an Encoding class is not going to just work for anything. If a "character" (possibly

Understanding Java unsigned numbers

北城以北 提交于 2019-12-30 04:58:25
问题 I want to understand how to convert signed number into unsigned. lets say I have this: byte number = 127; // '1111111' In order to make it unsigned I have to choose "bigger" data type 'short' and apply AND operator with value 0x00ff. short number2; number2 = number & 0x00ff; Why does it make the number unsigned? 回答1: Java doesn't actually have unsigned primitives. The value 127 is actually represented by '01111111' the first bit being the sign (0 is positive). An unsigned byte would be able

LSB/MSB handling in Java

六月ゝ 毕业季﹏ 提交于 2019-12-30 01:12:21
问题 If I have to handle values to be stored in bytes like 0x118, how do I split the LSB and MSB? I was trying the following way... I don't think that it's the right way: value = 0x118; Storing in bytes... result[5] = (byte) value; result[6] = (byte)(value << 8); ... What is the correct way? 回答1: This will do it: result[5] = (byte) (value & 0xFF); // Least significant "byte" result[6] = (byte) ((value & 0xFF00) >> 8); // Most significant "byte" I usually use bit masks - maybe they're not needed.

python - Steganographer File Handling Error for non plain-text files

匆匆过客 提交于 2019-12-29 09:20:07
问题 I've built a Python Steganographer and am trying to add a GUI to it. After my previous question regarding reading all kinds of files in Python. Since, the steganographer can only encode bytes in image. I want to add support to directly encode a file of any extension and encoding in it. For this, I am reading the file in binary and trying to encode it. It works fine for files which basically contains plain-text UTF-8 because it can easily encode .txt and .py files. My updated code is: from PIL

How do I convert a Bitmap to byte[]?

为君一笑 提交于 2019-12-29 08:27:11
问题 Basically I am inserting an image using the listviews inserting event, trying to resize an image from the fileupload control, and then save it in a SQL database using LINQ. I found some code to create a new bitmap of the content in the fileupload control, but this was to store it in a file on the server, from this source, but I need to save the bitmap back into the SQL database, which I think I need to convert back into a byte[] format. So how do I convert the bitmap to a byte[] format? If I

Display image from byte[ ]

拥有回忆 提交于 2019-12-29 07:16:11
问题 I use C#, wpf. I have an image, it is stored in the form of: byte[ ] public interface IFile { int Id { get; set; } byte[] FileData { get; set; } string FileName { get; set; } int? FileSize { get; set; } string FileExtension { get; set; } } How can I display my image (FileData byte[ ] ) on the form? <GroupBox BorderThickness="1"> <Image Source="..."/> </GroupBox> I have to write in Source="..." , if I create a temporary file from a byte[ ]? 回答1: Provided that you have a view model class that

String to Bytes Python without change in encoding

China☆狼群 提交于 2019-12-29 06:29:11
问题 I have this issue and I can't figure out how to solve it. I have this string: data = '\xc4\xb7\x86\x17\xcd' When I tried to encode it: data.encode() I get this result: b'\xc3\x84\xc2\xb7\xc2\x86\x17\xc3\x8d' I only want: b'\xc4\xb7\x86\x17\xcd' Anyone knows the reason and how to fix this. The string is already stored in a variable, so I can't add the literal b in front of it. 回答1: You cannot convert a string into bytes or bytes into string without taking an encoding into account. The whole

Request returns bytes and I'm failing to decode them

守給你的承諾、 提交于 2019-12-29 04:35:11
问题 Essentially I made a request to a website and got a byte response back: b'[{"geonameId:"703448"}..........'. I'm confused because although it is of type byte, it is very human readable and appears like a list of json. I do know that the response is encoded in latin1 from running r.encoding which returned ISO-859-1 and I have tried to decode it, but it just returns an empty string. Here's what I have so far: r = response.content string = r.decode("ISO-8859-1") print (string) and this is where