byte

how to convert byte value into int in objective-c

独自空忆成欢 提交于 2019-12-18 18:05:10
问题 Please tell me how to convert bytes to NSInteger/int in objective-c in iPhone programming? 回答1: What do you mean by "Bytes"? If you want convert single byte representing integer value to int (or NSInteger) type, just use "=": Byte b = 123; NSInteger x; x = b; as Byte (the same as unsigned char - 1 byte unsigned integer) and NSInteger (the same as int - 4 bytes signed integer) are both of simple integer types and can be converted automatically. Your should read more about " c data types " and

how to split 64bit integer to two 32bit integers

非 Y 不嫁゛ 提交于 2019-12-18 16:32:24
问题 I want to split a 64bit integer into two 32bit integers: var bigInt = 0xffffff; var highInt = bigInt >> 8 // get the high bits 0xfff var lowInt = bigInt // cut of the first part (with &)? console.log(highInt); // 0xfff console.log(lowInt); // 0xfff // set them together again var reBigInt = (highInt << 8) + lowInt; Unfortunately neither getting the highInt nor getting the lowInt works... Could somebody give me the answer how I need to use the bitwise operators? regards 回答1: EDIT JavaScript

C#: Implementing NetworkStream.Peek?

折月煮酒 提交于 2019-12-18 14:49:53
问题 Currently, there isn't a NetworkStream.Peek method in C#. What is the best way of implementing such a method which functions just like NetworkStream.ReadByte except that the returned byte is not actually removed from the Stream ? 回答1: If you don't need to actually retrieve the byte, you can refer to the DataAvailable property. Otherwise, you can wrap it with a StreamReader and invoke its Peek method. Note that neither of these are particularly reliable for reading from a network stream, due

Byte manipulation in PHP

爷,独闯天下 提交于 2019-12-18 14:13:09
问题 In PHP, if you have a variable with binary data, how do you get specific bytes from the data? For example, if I have some data that is 30 bytes long how do I get the first 8 bytes? Right now, I'm treating it like a string, using the substr() function: $data = //... $first8Bytes = substr($data, 0, 8); Is it safe to use substr with binary data? Or are there other functions that I should be using? 回答1: Generally all string functions in PHP are safe to use with raw bytes. The issue that mostly

Conversion of byte array containing hex values to decimal values

房东的猫 提交于 2019-12-18 13:37:46
问题 I am making application in c#.Here i want to convert a byte array containing hex values to decimal values.Suppose i have one byte array as array[0]=0X4E; array[1]=0X5E; array[2]=0X75; array[3]=0X49; Here i want to convert that hex array to decimal number like i want to concatenate first all bytes values as 4E5E7549 and after that conversion of that number to decimal.I dont want to convert each separate hex number to decimal.The decimal equivalent of that hex number is 1314813257.So please

Python-String to Bytes conversion. Double BackSlash issue

自作多情 提交于 2019-12-18 13:25:19
问题 I've got a problem. I've this string: a=O\x8c\x90\x05\xa1\xe2!\xbe If i use: c=str.encode(a) This is the result: b'O\\x8c\\x90\\x05\\xa1\\xe2!\\xbe' I need those double backslash to be single backslash and i really need that type of data to be BYTES. I need to return this: c=b'0\x8c\x90\x05\xa1\xe2!\xbe' And type(c)==bytes Any idea? 回答1: You can use str.decode() with encoding as unicode-escape . Then decode it back using the required encoding to get back your bytes array. Example - c = a

Convert from 2 or 4 bytes to signed/unsigned short/int

断了今生、忘了曾经 提交于 2019-12-18 13:25:08
问题 I have to convert bytes to signed/unsigned int or short. The methods below are correct? Which is signed and which unsigned? Byte order: LITTLE_ENDIAN public static int convertTwoBytesToInt1(byte b1, byte b2) { return (int) ((b2 << 8) | (b1 & 0xFF)); } VS. public static int convertTwoBytesToInt2(byte b1, byte b2) { return (int) (( (b2 & 0xFF) << 8) | (b1 & 0xFF)); } and public static int convertFourBytesToInt1(byte b1, byte b2, byte b3, byte b4){ return (int) ((b4<<24)+(b3<<16)+(b2<<8)+b1); }

Convert float[] to byte[] to float[] again

半世苍凉 提交于 2019-12-18 13:19:59
问题 So what I'm trying to do here is get a float[] , convert it to byte[] , send it through the network as a datagram packet and then convert it back to a byte[] at the receiving terminal. Now I know I can convert float[] to byte[] by using the getBytes[] method. But I don't know how to reverse the conversion. 回答1: I think you want to make use of the ByteBuffer class, which has putFloat and getFloat methods. 回答2: Another way... use ByteArrayOutputStream/DataOutputStream for output float fArr[] =

Bitwise AND, Bitwise Inclusive OR question, in Java

穿精又带淫゛_ 提交于 2019-12-18 12:28:29
问题 I've a few lines of code within a project, that I can't see the value of... buffer[i] = (currentByte & 0x7F) | (currentByte & 0x80); It reads the filebuffer from a file, stored as bytes, and then transfers then to buffer[i] as shown, but I can't understand what the overall purpose is, any ideas? Thanks 回答1: As the other answers already stated, (currentByte & 0x7F) | (currentByte & 0x80) is equivalent to (currentByte & 0xFF) . The JLS3 15.22.1 says this is promoted to an int : When both

Transferring ByteArray through Parcel returns NullPointerException

岁酱吖の 提交于 2019-12-18 12:13:14
问题 import android.os.Parcel; import android.os.Parcelable; public class MClass implements Parcelable { private byte[] _byte; public MClass() { } public MClass(Parcel in) { readFromParcel(in); } public byte[] get_byte() { return _byte; } public void set_byte(byte[] _byte) { this._byte = _byte; } public int describeContents() { return 0; } public void writeToParcel(Parcel dest, int flags) { dest.writeByteArray(_byte); } public void readFromParcel(Parcel in) { in.readByteArray(_byte); //LOE - Line