byte

How to get bytes of a String in Dart?

最后都变了- 提交于 2019-12-11 02:19:08
问题 How can I read the bytes of a String in dart? in Java it is possible through the String method getBytes() . See example 回答1: String foo = 'Hello world'; List<int> bytes = utf8.encode(foo); print(bytes); Output: [72, 101, 108, 108, 111, 32, 119, 111, 114, 108, 100] Also, if you want to convert back: String bar = utf8.decode(bytes); 回答2: There is a codeUnits getter that returns UTF-16 String foo = 'Hello world'; List<int> bytes = foo.codeUnits; print(bytes); [72, 101, 108, 108, 111, 32, 119,

How to assign byte[] as a pointer in C#

旧巷老猫 提交于 2019-12-11 02:18:56
问题 I have a function that generates a CRC check byte based on the content of any packet.The problem is in translating the function from C++ to C# C++ code: unsigned char GenerateCheckByte( char* packet, int length, unsigned long seed ) { if( !packet ) return 0; unsigned long checksum = 0xFFFFFFFF; length &= 0x7FFF; char* ptr = packet; unsigned long moddedseed = seed << 8; for( int i = 0; i < length; i++ ) checksum = ( checksum >> 8 ) ^ table[moddedseed + ( ( *(ptr++) ^ checksum ) & 0xFF )];

Error message when running telnet in python shell

情到浓时终转凉″ 提交于 2019-12-11 01:49:56
问题 Below is a minimal example of my code, which If you run, should recreate the problem I have. One thing I have encounter that the error does not appear if my raspberry pi (the thing I am using teller to connect to) is turned off or the internet cable is unplugged. #IMPORTS import time import telnetlib import sys import getpass #TELNET user = input("Please Enter Your Username: ") time.sleep(0.4) pass_ = input("Please Enter Your Password: ") bot = telnetlib.Telnet("192.168.1.128") bot.read_until

Length of binary data in python

为君一笑 提交于 2019-12-11 01:39:15
问题 I am using Python. I am trying to determine the correct length of bytes in a binary set of data. If I assign a variable the binary data... x = "aabb".decode("hex") is that the same as x = b'aabb' And if so, how do you get how many bytes that is? (It should be 2 bytes) When I try: len(x) I get 4 instead of 2 though... I am worried that x is turned into a string or something else I don't understand because the data types are so fluid in Python... 回答1: The length of binary data is just the len ,

Difference between C# and java big endian bytes using miscutil

扶醉桌前 提交于 2019-12-10 23:57:19
问题 I'm using the miscutil library to communicate between and Java and C# application using a socket. I am trying to figure out the difference between the following code (this is Groovy, but the Java result is the same): import java.io.* def baos = new ByteArrayOutputStream(); def stream = new DataOutputStream(baos); stream.writeInt(5000) baos.toByteArray().each { println it } /* outputs - 0, 0, 19, -120 */ and C#: using (var ms = new MemoryStream()) using (EndianBinaryWriter writer = new

c++ - Save the contents of a “std::vector<unsigned char>” to a file

旧城冷巷雨未停 提交于 2019-12-10 23:40:53
问题 I use the function below "writeFileBytes" to write the contents of a std::vector<unsigned char> to a file. I want to use the type "unsigned char" to save the file (note that is made a cast for "char"). The reason for that question is because "unsigned char" has compatibility with any byte ("00000000" bits, for example). When we use "char" we have some problems with the manipulation of certain "invalid" chars. See this topic What is the most suitable type of vector to keep the bytes of a file?

Most efficient way to xor byte array in vb.net

核能气质少年 提交于 2019-12-10 21:56:39
问题 I am making making an application in vb.net that will read files using a byte array as buffer, and create parity files for them by xoring the data... What would be the most efficient way of xoring a byte array? I have though of convertinbg the byte array to a bitarray and then run it trough an xor operation and turn it back to a byte array, but that sounds like a very processing expensive task, and i am worried that it might impact read/write speed... is there a better way to do this? thanks.

convert byte array to 16 bits float

大城市里の小女人 提交于 2019-12-10 19:53:53
问题 I have a network array of 2 bytes that I need to convert to float [values between -1 ... 1-2.E(-15)] examples : byte[] Arr1={0x70 , 0x54} //==> Result = 0.660 byte[] Arr2={0x10 , 0x37} //==> Result = 0.430 Any solutions to overpass this ? 回答1: What standard you have used that gave you {0x70 , 0x54} ? I have made a sample code for Half-precision floating point conversation according to IEEE 754-2008 standard. https://en.wikipedia.org/wiki/Half-precision_floating-point_format public static

How to read mixed file of byte and string

大城市里の小女人 提交于 2019-12-10 19:50:01
问题 I've a mixed file with a lot of string line and part of byte encoded data. Example: --Begin Attach Content-Info: /Format=TIF Content-Description: 30085949.tif (TIF File) Content-Transfer-Encoding: binary; Length=220096 II*II* Îh ÿÿÿÿÿÿü³küìpsMg›Êq™Æ™Ôd™‡–h7ÃAøAú áùõ=6?Eã½/ô|û ƒú7z:>„Çÿý<þ¯úýúßj?å¿þÇéöûþ“«ÿ¾ÁøKøÈ%ŠdOÿÞÈ<,Wþ‡ÿ·ƒïüúCÿß%Ï$sŸÿÃÿ÷‡þåiò>GÈù#ä|‘ò:#ä|Š":#¢:;ˆèŽˆèʤV‘ÑÑÑÑÑÑÑÑÑçIþ×o(¿zHDDDDDFp'.Ñ:ˆR:aAràÁ¬LˆÈù!ÿÿï[ÿ¯Äàiƒ"VƒDÇ)Ê6PáÈê$9C”9C†‡CD¡pE@¦œÖ{i~Úý¯kköDœ4ÉU”8`ƒt!l2G --End Attach--

Apostrophes are printing out as â\x80\x99

China☆狼群 提交于 2019-12-10 18:12:46
问题 import requests from bs4 import BeautifulSoup import re source_url = requests.get('http://www.nytimes.com/pages/business/index.html') div_classes = {'class' :['ledeStory' , 'story']} title_tags = ['h2','h3','h4','h5','h6'] source_text = source_url.text soup = BeautifulSoup(source_text, 'html.parser') stories = soup.find_all("div", div_classes) h = []; h2 = []; h3 = []; h4 =[] for x in range(len(stories)): for x2 in range(len(title_tags)): hold = []; hold2 = [] hold = stories[x].find(title