byte

C++: Bitwise AND

痞子三分冷 提交于 2019-12-10 00:28:28
问题 I am trying to understand how to use Bitwise AND to extract the values of individual bytes. What I have is a 4-byte array and am casting the last 2 bytes into a single 2 byte value. Then I am trying to extract the original single byte values from that 2 byte value. See the attachment for a screen shot of my code and values. The problem I am having is I am not able to get the value of the last byte in the 2 byte value. How would I go about doing this with Bitwise AND? Thanks for your help,

Quickest way (performance-wise) to turn a string into a byte[] array in C# using the ASCII character encoding

大憨熊 提交于 2019-12-09 16:09:46
问题 What's the fastest way to turn a string into a byte[] array in C#? I'm sending tonnes of string data through sockets and need to optimize every single operation. Currently I transform the strings in to byte[] arrays before sending using: private static readonly Encoding encoding = new ASCIIEncoding(); //... byte[] bytes = encoding.GetBytes(someString); socket.Send(bytes); //... 回答1: If all your data is really going to be ASCII, then you may be able to do it slightly faster than ASCIIEncoding

Why does java have no byte type suffix? [closed]

大憨熊 提交于 2019-12-09 15:18:44
问题 As it currently stands, this question is not a good fit for our Q&A format. We expect answers to be supported by facts, references, or expertise, but this question will likely solicit debate, arguments, polling, or extended discussion. If you feel that this question can be improved and possibly reopened, visit the help center for guidance. Closed 9 years ago . So java has a long type suffix for literals: (123L), a double type suffix (43.21D), a floating point suffix (1.234F). So ... why no

Integer Byte Swapping in C++

折月煮酒 提交于 2019-12-09 12:28:39
问题 I'm working on a homework assignment for my C++ class. The question I am working on reads as follows: Write a function that takes an unsigned short int (2 bytes) and swaps the bytes. For example, if the x = 258 ( 00000001 00000010 ) after the swap, x will be 513 ( 00000010 00000001 ). Here is my code so far: #include <iostream> using namespace std; unsigned short int ByteSwap(unsigned short int *x); int main() { unsigned short int x = 258; ByteSwap(&x); cout << endl << x << endl; system(

zlib from C++ to C#(How to convert byte[] to stream and stream to byte[])

|▌冷眼眸甩不掉的悲伤 提交于 2019-12-09 12:19:21
问题 My task is to decompress a packet(received) using zlib and then use an algoritm to make a picture from the data The good news is that I have the code in C++,but the task is to do it in C# C++ //Read the first values of the packet received DWORD image[200 * 64] = {0}; //used for algoritm(width always = 200 and height always == 64) int imgIndex = 0; //used for algoritm unsigned char rawbytes_[131072] = {0}; //read below unsigned char * rawbytes = rawbytes_; //destrination parameter for

Large mutable byte array in Erlang

 ̄綄美尐妖づ 提交于 2019-12-09 09:42:08
问题 As I am writing a simple Minecraft server application in Erlang, I am now concerned with the question of how to efficiently store and modify chunk data. For those who don't know about Minecraft's internals: I need to store a lot of binaries (100-1000) of up to 32kB size in memory. Until this point Erlang's builtin binaries are sufficient. But the server has to read and change some bytes (by their id) in these binaries quite often and I don't want to copy them around all the time. A nice to

Get size of String w/ encoding in bytes without converting to byte[]

我们两清 提交于 2019-12-09 08:30:39
问题 I have a situation where I need to know the size of a String /encoding pair, in bytes, but cannot use the getBytes() method because 1) the String is very large and duplicating the String in a byte[] array would use a large amount of memory, but more to the point 2) getBytes() allocates a byte[] array based on the length of the String * the maximum possible bytes per character. So if I have a String with 1.5B characters and UTF-16 encoding, getBytes() will try to allocate a 3GB array and fail,

How do I find out how many bytes a character has?

有些话、适合烂在心里 提交于 2019-12-09 08:29:45
问题 I was wondering how do I find out how many bytes does a character have? 回答1: If you want to find out how many UTF-8 bytes a letter in a PHP string has then: print strlen(mb_substr($string, 0, 1, "utf-8")); strlen() returns the raw byte length, while mb_substr() returns a "character" according to the charset/encoding. In this example from position 0 . 回答2: ASCII is 7 bits. Most other languages use 8 bits (1 byte). Many eastern languages (Chinese, Japanese) use 16 bits (2 bytes). Unicode is

how to convert CString to Bytes

断了今生、忘了曾经 提交于 2019-12-09 07:08:24
i am actually tryin to convert a csharp code to c... below is the C# code.. CString data = "world is beautiful"; Byte[] quote = ASCIIEncoding.UTF8.GetBytes(data); in the above code... it converts the string into bytes..similarily is ther a way that i can convert it using C.. Can any body tell what wud be the quivalent code in C? Please help me guys Well CString is a C++ class so doing it in C is a little unlikely. But if you wish to get it as a standard multi-byte encoded string then you can do the following CString data = "world is beautiful"; CStringA mbStr = data; char* bytes = mbStr

Initialize unsigned byte array using hex number

喜欢而已 提交于 2019-12-09 05:59:45
问题 I know that unsigned byte is missing in Java Then how can I initialize the byte array using integer from 0 to 255 (in hex) ? final byte assoc_resp_msg_int[] = new byte[] { 0xe3, 0x00, //APDU CHOICE Type(AareApdu) 0x00, 0x2c, //CHOICE.length = 44 0x00, 0x00, //result=accept 0x50, 0x79, //data-proto-id = 20601 0x00, 0x26, //data-proto-info length = 38 0x80, 0x00, 0x00, 0x00, //protocolVersion 0x80, 0x00, //encoding rules = MDER 0x80, 0x00, 0x00, 0x00, //nomenclatureVersion 0x00, 0x00, 0x00,