byte

Understanding of the Audio Recorder read() buffer [closed]

心不动则不痛 提交于 2019-12-08 02:25:17
问题 Closed. This question is off-topic. It is not currently accepting answers. Want to improve this question? Update the question so it's on-topic for Stack Overflow. Closed 5 years ago . I really hope someone could help me. I am currently working with the Android "Audio Recorder" and everything works fine. The next step would be to work with the bytes I got back from the buffer when I called read() . Being a Web Developer for quit some time, I lack some basics - mostly about the bytes stored in

Convert int to byte as HEX in C#

有些话、适合烂在心里 提交于 2019-12-08 01:57:30
问题 I need to send a Hex string over the serial to a device, I do that now like this: byte[] c = new byte[3]; c[0] = 0x57; c[1] = 0x30; ComPort.Write(c,0,c.Length ); Now I need to convert a value of int like 30 to c[1] = 0x30 or a int value of 34 gives c[1] = 0x34 . I hope you see what I mean. So how can I mange this? 回答1: This format is called binary-coded decimal. For two-digit numbers, integer-divide by ten and multiply by sixteen, then add back the remainder of the division by ten: int num =

How can I convert bytes object to decimal or binary representation in python?

家住魔仙堡 提交于 2019-12-08 01:49:00
问题 I wanted to convert an object of type bytes to binary representation in python 3.x. For example, I want to convert the bytes object b'\x11' to the binary representation 00010001 in binary (or 17 in decimal). I tried this: print(struct.unpack("h","\x11")) But I'm getting: error struct.error: unpack requires a bytes object of length 2 回答1: Starting from Python 3.2, you can use int.from_bytes. Second argument, byteorder , specifies endianness of your bytestring. It can be either 'big' or 'little

CHIP-8 game has an odd number of bytes

岁酱吖の 提交于 2019-12-08 01:44:49
问题 I have been working on a CHIP8 emulator and am using the hex-editor in notepad++ to view the hex values. I happened to notice that some of the games like "Blitz" by David Winter have an odd number of bytes. In CHIP8, each opcode is 2 bytes long, so there should be an even number of bytes, right? 回答1: As you can see in the hex dump, the author has embedded the string BLITZ By David WINTER into the ROM. Maybe this string is shown somewhere in the game, or maybe it's just his little way of

Convert Bytes to Image ASP.NET c# and use it in Image1.Url

淺唱寂寞╮ 提交于 2019-12-08 00:57:41
问题 I have a WEB-APP that is a Web-Cam App that takes images and stores into a database as bytes, Now with that being said I also don't want to save the images those are taken and save it in any kind of folder right now the only way to show the image that is captured for me to save it and view it again to do that I have a input stream that's fired when the capture image is clicked. using (StreamReader reader = new StreamReader(Request.InputStream)) { hexString = Server.UrlEncode(reader.ReadLine()

Reading/Writing Nibbles (without bit fields) in C/C++

瘦欲@ 提交于 2019-12-07 17:47:03
问题 Is there an easy way to read/write a nibble in a byte without using bit fields? I'll always need to read both nibbles, but will need to write each nibble individually. Thanks! 回答1: Use masks : char byte; byte = (byte & 0xF0) | (nibble1 & 0xF); // write low quartet byte = (byte & 0x0F) | ((nibble2 & 0xF) << 4); // write high quartet You may want to put this inside macros. 回答2: The smallest unit you can work with is a single byte. If you want to manage the bits you should use bitwise operators.

What is the best way (performance-wise) to test whether a value falls within a threshold?

泄露秘密 提交于 2019-12-07 15:30:42
That is, what is the fastest way to do the test if( a >= ( b - c > 0 ? b - c : 0 ) && a <= ( b + c < 255 ? b + c : 255 ) ) ... if a, b, and c are all unsigned char aka BYTE . I am trying to optimize an image scanning process to find a sub-image, and a comparison such as this is done about 3 million times per scan, so even minor optimizations could be helpful. Not sure, but maybe some sort of bitwise operation? Maybe adding 1 to c and testing for less-than and greater-than without the or-equal-to part? I don't know! orlp Well, first of all let's see what you are trying to check without all

How to interpret 4 bytes as a 32-bit float using Python

拥有回忆 提交于 2019-12-07 15:11:31
问题 I am sort of a novice to the Python language and am having a hard time doing something I could very easily do with C++ or Java but for some reason seems so convoluted to do in Python. I have the following four bytes in an array (in big endian order): [0x64, 0xD8, 0x6E, 0x3F] I already know beforehand what these bytes represent. They specify the following 32-bit floating-point number: 0.932989 What are the steps I need to perform using Python (preferably v3.2.1 and without using extra imports)

how to convert Image to string the most efficient way?

元气小坏坏 提交于 2019-12-07 14:14:41
问题 I want to convert an image file to a string. The following works: MemoryStream ms = new MemoryStream(); Image1.Save(ms, ImageFormat.Jpeg); byte[] picture = ms.ToArray(); string formmattedPic = Convert.ToBase64String(picture); However, when saving this to a XmlWriter, it takes ages before it's saved(20secs for a 26k image file). Is there a way to speed this action up? Thanks, Raks 回答1: There are three points where you are doing large operations needlessly: Getting the stream's bytes Converting

How to search an array of bytes for “StringA”?

一笑奈何 提交于 2019-12-07 13:48:13
问题 Using FreePascal (or Delphi if no FP examples), given a 2048 byte buffer that is as an "array of bytes", how can I search the buffer for "StringA"? var Buffer : array[1..2048] of byte; ... repeat i := 0; BlockRead(SrcFile, Buffer, SizeOf(Buffer), NumRead); // Now I want to search the buffer for "StringA"? ... Thankyou 回答1: I think this will work in fpc without extra Unicode/AnsiString conversion : function Find(const buf : array of byte; const s : AnsiString) : integer; //returns the 0-based