uint16

Equivalent of BitConverter.ToUInt16 of C# for Java 7 [duplicate]

左心房为你撑大大i 提交于 2020-07-10 10:27:44
问题 This question already has an answer here : Equivalent of BitConverter.ToUInt16 of C# for Java (1 answer) Closed 9 days ago . My question is about Java. I need a method that returns an unsigned 16-bit integer converted from two bytes at the specified position in a byte array. In other words I need the equivalent of the method BitConverter.ToUInt16 of C# for Java that works with Java 7. In C# using System; using System.IO; using System.Linq; using System.Collections.Generic; namespace CSharp

Equivalent of BitConverter.ToUInt16 of C# for Java

☆樱花仙子☆ 提交于 2020-07-03 13:26:41
问题 My question is about Java What is the equivalent of BitConverter.ToUInt16 for Java? I am trying to translate this method of C#: public static implicit operator ushort(HashlinkReader p) { ushort tmp = BitConverter.ToUInt16(p.Data.ToArray(), p.Position); p.Position += 2; return tmp; } to Java: public static int convertToInt(HashlinkReader p) { byte[] byteArray = new byte[p.Data.size()]; for (int index = 0; index < p.Data.size(); index++) { byteArray[index] = p.Data.get(index); } int tmp =

Equivalent of BitConverter.ToUInt16 of C# for Java

一世执手 提交于 2020-07-03 13:25:48
问题 My question is about Java What is the equivalent of BitConverter.ToUInt16 for Java? I am trying to translate this method of C#: public static implicit operator ushort(HashlinkReader p) { ushort tmp = BitConverter.ToUInt16(p.Data.ToArray(), p.Position); p.Position += 2; return tmp; } to Java: public static int convertToInt(HashlinkReader p) { byte[] byteArray = new byte[p.Data.size()]; for (int index = 0; index < p.Data.size(); index++) { byteArray[index] = p.Data.get(index); } int tmp =

Convert float values to uint8 array in javascript

我们两清 提交于 2019-12-24 09:58:16
问题 I have a Float32Array with values from an audio file.I want to save it as a .wav file so I need to convert that values to a Uint8array. To convert from uint8 to float I convert first to an int16 array and then to a Float32Array (Convert int16 array to float) How can I do that conversion in the other direction? 回答1: You can convert to an ArrayBuffer , copy the data into and then create a byte view of this buffer : var data = new Float32Array([0.1, 0.2, 0.3]); var buffer = new ArrayBuffer(data

Convert int16 array to float

半城伤御伤魂 提交于 2019-12-24 08:15:23
问题 I have an array of bytes from an audio file and I want to convert it into data that I can process to filter the audio signal. I have an array like this: [239,246,96,247.....]; Each element is a uint8 byte Each 2 bytes(16 bits) represent a sample,so I converted this array into a int16 element array. How can I then convert this array into a signal with values in the range[-1,1]? 回答1: You already have your signed int16's so you just have to divide by the min and max int16 value respective to the

Uint16Array to Uint8Array

隐身守侯 提交于 2019-12-22 10:35:14
问题 I have a basic question. Say I have a Uint16Array and I have number 4 in it. data_16=new Uint16Array([4]); Now I have a length 1 and byteLength 2; how do i convert this to Uint8Array. I do not want to create a new view. data_8 = new Uint8Array(data_16) If I do this I get array length 1 and byteLength 1. This is not what I want. I need to stretch that 16 bit value in 16array into 8 bit values so that 8bit array so it would end up with 2 values int 8 bit array. I can just create a funtion which

Proper way for casting uint16 to int16 in Go

◇◆丶佛笑我妖孽 提交于 2019-12-14 04:19:38
问题 Bitwise manipulation and Go newbie here :D I am reading some data from sensor with Go and I get it as 2 bytes - let's say 0xFFFE . It is easy too cast it to uint16 since in Go we can just do uint16(0xFFFE) but what I need is to convert it to integer, because the sensor returns in fact values in range from -32768 to 32767. Now I thought "Maybe Go will be this nice and if I do int16(0xFFFE) it will understand what I want?" , but no. I ended up using following solution (I translated some python

How can I pass in a pointer to a pointer of a UInt16 array to a Marshalled function?

孤街浪徒 提交于 2019-12-14 02:32:10
问题 I'm attempting to send a pointer to a pointer of a UInt16 array to a marshalled function like so in C#: C++: int foo(Unsigned_16_Type** Buffer_Pointer); C#: [DllImport("example.dll")] public static extern int foo(IntPtr Buffer_Pointer); UInt16[] bufferArray = new UInt16[32]; IntPtr p_Buffer = (IntPtr)Marshal.AllocCoTaskMem(Marshal.SizeOf(typeof(UInt16)) * bufferArray.Length); Marshal.Copy(bufferArray, 0, p_Buffer, bufferArray.Length); //Issue is here GCHandle handle = GCHandle.Alloc(p_Buffer,

How to convert UInt16 to UInt8 in Swift 3?

ⅰ亾dé卋堺 提交于 2019-12-11 08:54:08
问题 I want to convert UInt16 to UInt8 array, but am getting the following error message: 'init' is unavailable: use 'withMemoryRebound(to:capacity:_)' to temporarily view memory as another layout-compatible type. The code: let statusByte: UInt8 = UInt8(status) let lenghtByte: UInt16 = UInt16(passwordBytes.count) var bigEndian = lenghtByte.bigEndian let bytePtr = withUnsafePointer(to: &bigEndian) { UnsafeBufferPointer<UInt8>(start: UnsafePointer($0), count: MemoryLayout.size(ofValue: bigEndian)) }

How do I printf() a uint16_t?

为君一笑 提交于 2019-12-09 15:08:30
问题 I need to use printf() to print a uint16_t. This SO answer (How to print uint32_t and uint16_t variables value?) says I need to use inttypes.h. However, I'm working on an embedded system and inttypes.h is not available. How do I print a uint16_t when the format specifier for a uint16_t is not available? 回答1: An obvious way is: printf("%u\n", (unsigned int)x); The unsigned int is guaranteed to be at least 16 bits, so this is not a lossy conversion. 回答2: You should use the style of inttypes.h