byte

Get File Bytes from Resource file in C#

馋奶兔 提交于 2020-01-03 15:34:14
问题 I used to store the resources in the actual project, but I've switched to using a resource file instead. Originally I could ready the bytes for a file, but I'm finding it difficult doing this with a resource file. Any suggestions would be greatly appreciated. 回答1: public static byte[] ReadResource(string resourceName) { using (Stream s = Assembly.GetExecutingAssembly().GetManifestResourceStream(resourceName)) { byte[] buffer = new byte[1024]; using (MemoryStream ms = new MemoryStream()) {

What is the easiest way to set custom binary data messages in Java?

亡梦爱人 提交于 2020-01-03 15:31:31
问题 Coming from the world of C# and brushing up on Java, I have learned that there are no unsigned bytes/ints. I am trying to find out what is the easiest way build up custom binary messages such as the following example: As you can see, certain integer values need to put into a 3 bit slot. others values are single bit flags, or other size fields. From what I have read, I should work in the "next larger" primitive, such as building binary bytes in integers using bit wise operators. Are there

Store a color in Java - byte;byte;byte vs. byte[3] vs int

前提是你 提交于 2020-01-03 13:15:07
问题 I need to store a ton of RGB color objects. These are taking up between 8% & 12% of the total memory of my app for some common usages. I presently have it defined as follows: class MyColor { byte red; byte green; byte blue; } I assume that (most) JVMs actually use an int for each of those entries. The easiest alternative is: class MyColor { byte [] color = new byte[3]; private static final int red = 0; private static final int green = 1; private static final int blue = 2; } Will that put the

How to properly decode .wav with Python

谁说胖子不能爱 提交于 2020-01-03 12:33:52
问题 I am coding a basic frequency analisys of WAVE audio files, but I have trouble when it comes to convertion from WAVE frames to integer. Here is the relevant part of my code: import wave track = wave.open('/some_path/my_audio.wav', 'r') byt_depth = track.getsampwidth() #Byte depth of the file in BYTES frame_rate = track.getframerate() buf_size = 512 def byt_sum (word): #convert a string of n bytes into an int in [0;8**n-1] return sum( (256**k)*word[k] for k in range(len(word)) ) raw_buf =

How to properly decode .wav with Python

六月ゝ 毕业季﹏ 提交于 2020-01-03 12:33:21
问题 I am coding a basic frequency analisys of WAVE audio files, but I have trouble when it comes to convertion from WAVE frames to integer. Here is the relevant part of my code: import wave track = wave.open('/some_path/my_audio.wav', 'r') byt_depth = track.getsampwidth() #Byte depth of the file in BYTES frame_rate = track.getframerate() buf_size = 512 def byt_sum (word): #convert a string of n bytes into an int in [0;8**n-1] return sum( (256**k)*word[k] for k in range(len(word)) ) raw_buf =

How to properly decode .wav with Python

这一生的挚爱 提交于 2020-01-03 12:33:07
问题 I am coding a basic frequency analisys of WAVE audio files, but I have trouble when it comes to convertion from WAVE frames to integer. Here is the relevant part of my code: import wave track = wave.open('/some_path/my_audio.wav', 'r') byt_depth = track.getsampwidth() #Byte depth of the file in BYTES frame_rate = track.getframerate() buf_size = 512 def byt_sum (word): #convert a string of n bytes into an int in [0;8**n-1] return sum( (256**k)*word[k] for k in range(len(word)) ) raw_buf =

Writing bytes from a struct into a file with c#

风流意气都作罢 提交于 2020-01-03 03:24:25
问题 Good morning everyone! I'm with a new problem here. I have to write down a data that comes from a struct that I declared in my sistem. The struct I created has only two fields and I use to to later conevrt it into bytes. [StructLayout(LayoutKind.Sequential, CharSet = CharSet.Ansi, Pack = 1)] public struct MyStructData { public short Id; [MarshalAs(UnmanagedType.ByValTStr, SizeConst = 20)] public string Name; } I convert this struct in bytes with the following code: private byte[] getBytes

How to store mp3 as bytes in sql server [duplicate]

ぃ、小莉子 提交于 2020-01-03 02:41:07
问题 This question already has answers here : Closed 9 years ago . Possible Duplicate: how to read and write MP3 to database Hi I need to read and store mp3 files as bytes in sql server and C#.. How can I do that? 回答1: SQL Server BLOB (Binary Large Object) lets you store image and mp3 data as raw binary in database. if you want get something up and running quickly, check this one. http://www.databasejournal.com/features/mssql/article.php/3724556/Storing-Images-and-BLOB-files-in-SQL-Server-Part-2

Convert a string of integers to byte array in Ruby

微笑、不失礼 提交于 2020-01-03 00:32:08
问题 I have a string of integer "72101108108111" but it is a string representing bytes of original string "Hello". How can I convert "72101108108111" to Ascii string "Hello" in Ruby? 回答1: s = '72101108108111' pattern=/^[a-zA-Z]/ index,res=0,'' while index<s.size len=0 while (s[index..index+len].to_i.chr=~pattern).nil? len+=1 end res << s[index..index+len].to_i.chr index+=len+1 end p res Try this , because the length of every string to be decoded is not certain. For example, "72->'H' , 101->'e' ,

How to improve speed with Receipt printer and ESC/POS commands in Java

倾然丶 夕夏残阳落幕 提交于 2020-01-02 06:19:32
问题 I have an application that communicates with a thermal printer in Java and makes the thermal printer print receipts with a barcode/emphasis/different sizes and so forth using a Star tsp 100 Printer. I can make the program print exaclty what i like but the printer is very slow. I believe the reason is that I am using non-preferable way/method of sending the byte commands. public static void Command(byte[] bytes) throws Exception{ //The bytes array is the argument, consisting of a byte[] array