byte

printf too smart casting from char to int?

不想你离开。 提交于 2019-12-23 07:57:24
问题 Why does the following call: printf("%d %d", 'a', 'b'); result in the "correct" 97 98 values? %d indicates the function has to read 4 bytes of data, and printf shouldn't be able to tell the type of the received arguments (besides the format string), so why isn't the printed number |a||b||junk||junk| ? Thanks in advance. 回答1: In this case, the parameters received by printf will be of type int . First of all, anything you pass to printf (except the first parameter) undergoes "default promotions

TypeError: must be string without null bytes, not str

六月ゝ 毕业季﹏ 提交于 2019-12-23 07:48:32
问题 I'm trying to run this code, to run the same command (with little changes) with every frame that I have: traj.reset() import os #os.chdir(outname) for i, frame in enumerate(traj): frame.superpose() comando = "python hollow.py -c constraint -o hollow_%s.pdb urei%s.pdb" % (i, i) os.system(comando) pml_cmd = "pymol urei%s.pdb hollow_%s.pdb -c -d 'as cartoon, urei%s;color gray90, urei%s;center chain A;set_view (\-0.605158150,0.089404292,0.791067421,\0.795849979,0.093013920,0.598304033,\-0

TypeError: must be string without null bytes, not str

旧巷老猫 提交于 2019-12-23 07:48:26
问题 I'm trying to run this code, to run the same command (with little changes) with every frame that I have: traj.reset() import os #os.chdir(outname) for i, frame in enumerate(traj): frame.superpose() comando = "python hollow.py -c constraint -o hollow_%s.pdb urei%s.pdb" % (i, i) os.system(comando) pml_cmd = "pymol urei%s.pdb hollow_%s.pdb -c -d 'as cartoon, urei%s;color gray90, urei%s;center chain A;set_view (\-0.605158150,0.089404292,0.791067421,\0.795849979,0.093013920,0.598304033,\-0

Is there a string type in Java based on on an 8-bit byte array?

99封情书 提交于 2019-12-23 05:08:50
问题 Is there any string type/class in Java (standard or otherwise) that is based on an array of the 8-bit byte type, and not the 16-bit char type? I really like the std::string type in C++, as it works very well with parsing base256 (binary) data... I went ahead and wrote a little class that provides most of the features I need (below), but a better one would be appreciated! public class stdstring extends Object { private byte [] bytedata; public stdstring() { bytedata = new byte[0]; } public

Scaling An Array (Matrix)

偶尔善良 提交于 2019-12-22 17:37:11
问题 The intention of this program is to create a larger array of bytes scaled up by a factor of 10 from the original array. For example, the 1 in [0][0] should be a 10x10 square of 1's in the new array. I provide the code and the output, which seems to work properly during population of the larger array, but then prints different values. I'm currently experimenting with just the rows in order to limit the number of variables I'm dealing with during testing. Can anyone think of a reason why this

Getting wrong bytes from Java compared to C#

我是研究僧i 提交于 2019-12-22 11:35:13
问题 So I have some FRX binary files from which I am attempting to get string captions using Java's binary reading methods. I was capable of doing so, and specifying the region in which to read bytes in C# using the following program : using System; using System.Collections.Generic; using System.Text; using System.IO; public class GetFromFRX { public static void Main() { StringBuilder buffer = new StringBuilder(); using (BinaryReader b = new BinaryReader(File.Open("frmResidency.frx", FileMode.Open

get all possible single bytes in python

萝らか妹 提交于 2019-12-22 11:04:27
问题 I'm trying to generate all possible bytes to test for a machine learning algorithm (8-3-8 mural network encoder). is there a way to do this in python without having 8 loops? Could permutations help? I'd prefer an elegant way to do this, but I'll take what I can get at the moment. desired output: [0,0,0,0,0,0,0,0] [0,0,0,0,0,0,0,1] [0,0,0,0,0,0,1,0] [0,0,0,0,0,0,1,1] [0,0,0,0,0,1,0,0] [0,0,0,0,0,1,0,1] . . . [1,1,1,1,1,1,1,1] 回答1: Yes, there is, itertools.product: import itertools itertools

C# - Can I use an array initializer to build one byte array out of another?

可紊 提交于 2019-12-22 10:59:14
问题 I'd like to use an array initializer to build one byte array out of another byte array as well as some other bytes that form a header/trailer. Basically, I'd like to do something like this: byte[] DecorateByteArray(byte[] payload) { return new byte[] { 0, 1, 2, payload.GetBytes(), 3, 4, 5}; } GetBytes() above is fictional, unfortunately. Is there any nice/elegant way to do this? I solved this by using a BinaryWriter to write everything to a MemoryStream , and then converting this into a byte

Convert Word of interop object to byte [] without saving physically

醉酒当歌 提交于 2019-12-22 09:55:47
问题 I have an object created in memory using Microsoft.Office.Interop and Microsoft.Office.Word and with all created, paragraphs, tables and the like. I need this object to generate a content byte [] to feed one field of the same type in a table. The problem that I can not save it in any way physically with a oDoc.Save ("path") in order to use a FileStream and solve my problem. Have tried several solutions and how to use the clipboard, and did not work. Any solution? 回答1: Do you really have to

How to define a single byte variable in go lang

﹥>﹥吖頭↗ 提交于 2019-12-22 09:19:46
问题 I am a newbie to golang and want to find a way to define a single byte variable. It's a demo program in Effective Go reference. package main import ( "fmt" ) func unhex(c byte) byte{ switch { case '0' <= c && c <= '9': return c - '0' case 'a' <= c && c <= 'f': return c - 'a' + 10 case 'A' <= c && c <= 'F': return c - 'A' + 10 } return 0 } func main(){ // It works fine here, as I wrap things with array. c := []byte{'A'} fmt.Println(unhex(c[0])) //c := byte{'A'} **Error** invalid type for