byte

Convert byte[] to original 2d array

孤街浪徒 提交于 2019-12-12 04:33:31
问题 I've taken a 2D array of UInt16 values, and converted it to raw bytes. I would like to take those bytes and convert them back into the original 2D array, but I'm unsure of how to do this when I only have the bytes, i.e., is there a way to determine the dimensions of an original array when all you have is that array converted to bytes? Here's my code: UInt16[,] dataArray = new UInt16[,] { {4, 6, 2}, {0, 2, 0}, {1, 3, 4} }; long byteCountUInt16Array = dataArray.GetLength(0) * dataArray

outputStream.write() for int[] array

怎甘沉沦 提交于 2019-12-12 04:18:00
问题 I'm looking for something that does the same thing than outputStream.write() but which will accept an array of int. Actually, I'm using this one : outputStream.write() but this one accepts only byte , byte[] or int . I could use the byte[] but the values I want to send are [255,44,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,255] so I can use the byte[] because there range are only from -127 to 127 :/ It's to send a command on a Port_Com which accept only packet of 19 bytes and must be start and end with

How to convert NSData to Array of UInt8 ins iOS Objective C?

痴心易碎 提交于 2019-12-12 04:06:18
问题 I have Swift code for convert this method: func DATA_TO_UINT8(_ d:Data) -> Array<UInt8> { return d.withUnsafeBytes { [UInt8](UnsafeBufferPointer(start: $0, count: (d.count))) } } and now i want it in Objective C . 回答1: To produce a stack based array try something like (code typed directly into answer, expect errors): NSData *data = ... UInt8 buf[data.length]; // local stack array [data getBytes:buf length:data.length]; If you want a heap array you will need to use malloc to allocate the

What does a b prefix before a python string mean?

倾然丶 夕夏残阳落幕 提交于 2019-12-12 03:48:13
问题 In a python source code I stumbled upon I've seen a small b before a string like in: b"abcdef" I know about the u prefix signifying a unicode string, and the r prefix for a raw string literal. What does the b stand for and in which kind of source code is it useful as it seems to be exactly like a plain string without any prefix? 回答1: This is Python3 bytes literal. This prefix is absent in Python 2.5 and older (it is equivalent to a plain string of 2.x, while plain string of 3.x is equivalent

bytes object has no attribute find_all

你说的曾经没有我的故事 提交于 2019-12-12 03:24:50
问题 I've been trying for the last 3 hours to scrape this website and get the rank, name, wins, and losses of each team. When implementing this code: import requests from bs4 import BeautifulSoup halo = requests.get("https://www.halowaypoint.com/en-us/esports/standings") page = BeautifulSoup(halo.content, "html.parser") final = page.encode('utf-8') print(final.find_all("div")) I keep getting this error If anyone can help me out then it would be much appreciated! Thanks! 回答1: You are calling the

How can I construct a Python string that is 16 bytes long?

生来就可爱ヽ(ⅴ<●) 提交于 2019-12-12 03:23:00
问题 When I make a Python string of one character, i.e. txt = "h" and I check its size, I get import sys sys.getsizeof(txt) 34 If one character is 34 bytes, how do I make a String of 16 byes? P.S. I'm playing around with PyCrypto AES, in OFB Mode, which required input of 16 bytes 回答1: getsizeof does not return the actual size of the string but it accounts for additional garbage collector overhead. As shown bellow test starts as an empty string but memory allocated for it is not zero due to reasons

convert string to hex and back with different encoding

主宰稳场 提交于 2019-12-12 03:14:52
问题 I want to convert a String value to hex and then back to it's ascii value. when I'm converting it to the hex value i'm doing it with the charset - cp424 . this is what i'm trying to do: String str = "abcאבג"; String hexString = Hex.encodeHexString(str.getBytes("cp424")); //some action String original_value = Hex.decodeHex(hexString.toCharArray()).toString(); My problem is beacuse i'm using cp424 when converting to hex I need when converting back to get it back to the defult charset. I tried

How can add more space if NSData < fixed size in Cocoa

一个人想着一个人 提交于 2019-12-12 02:52:52
问题 I have a problem: I used below codes to get data from NSData , but I want to get data from [0;2048] bytes . If my data > 2048* strong text *, it can run fine but if my data < 2048 , it'll wrong. So that I want to add more some space at last if my data < 2048 to enough 2048 bytes . Can you help me? Thanks so much. NSData *data = [NSData dataWithBytes:[arrayText UTF8String] length:[arrayText lengthOfBytesUsingEncoding:NSUTF8StringEncoding]]; NSData *datawrite = [data subdataWithRange

How to display bytes received per second in C#

一曲冷凌霜 提交于 2019-12-12 02:46:44
问题 I'm trying to display the received bytes per second and have them displayed in the console once a second. The I am presented with a Invalid Operation Exception once it reaches .nextvalue. PerformanceCounter NetworkDownSpeed = new PerformanceCounter("Network Interface", "Bytes Received/sec"); float CurrentNetworkDownSpeed = (int)NetworkDownSpeed.NextValue(); while (true) { Console.WriteLine("Current Network Download Speed: {0}MB", CurrentNetworkDownSpeed); Thread.Sleep(1000); } 回答1: Sorry for

How do I copy bytes into a struct variable in C#?

我的未来我决定 提交于 2019-12-12 02:25:35
问题 I have a struct abc and I want to copy bytes into a struct variable. Similar to memcpy in C/C++. I receive the bytes over socket and they are the bytes of the same struct abc variable. [StructLayout(LayoutKind.Sequential, Pack = 1)] public struct abc { public int a; public int b; public float c; public char[] d; //30 size } 回答1: You can convert the byte array to your structure as follows : int size = Marshal.SizeOf(typeof(abc)); IntPtr ptr = Marshal.AllocHGlobal(size); Marshal.Copy(arr, 0,