byte

How to display a hex/byte value in Java

帅比萌擦擦* 提交于 2019-12-23 20:14:57
问题 int myInt = 144; byte myByte = /* Byte conversion of myInt */; Output should be myByte : 90 (hex value of 144). So, I did: byte myByte = (byte)myInt; I got output of myByte : ffffff90 . :( How can I get rid of those ffffff s? 回答1: byte is a signed type. Its values are in the range -128 to 127; 144 is not in this range. There is no unsigned byte type in Java. If you are using Java 8, the way to treat this as a value in the range 0 to 255 is to use Byte.toUnsignedInt : String output = String

Is writing bytes at the end of EXE file safe?

偶尔善良 提交于 2019-12-23 18:43:57
问题 I've heard that if we append some bytes at the end of an EXE file, it can still work properly. Is it true in all case? And is it a safe way? I intend to write the demo using data in the program execution file, so it can be safe (at least to normal user) and I don't have to store data anywhere else. 回答1: This is impossible to answer with a certain Yes or No. I assume you will store data at the end of your executable in lieu of storing program state in a configuration file. I further assume you

MemoryStream from bytes array with different types of data

亡梦爱人 提交于 2019-12-23 16:34:06
问题 I want to create a memory stream which contains int32, int16, single values. Using binarywriter is useless so i tried to make bytes array. Because values are in different types, I don't know how to do it properly. So I try do like that: byte[] tab = new byte[]{2,0,0,0,3,0,3,0} - 2 is int32 (four bytes), another two 3 are int16 (two bytes) that works fine, but when i want to add some single values, it generates errors. I cant do like that : byte[] tab = new byte[]{2,0,0,0,3,0,3,0,4.4f,5.6f} I

How should I decode bytes (using ASCII) without losing any “junk” bytes if xmlcharrefreplace and backslashreplace don't work?

微笑、不失礼 提交于 2019-12-23 15:33:10
问题 I have a network resource which returns me data that should (according to the specs) be an ASCII encoded string. But in some rare occasions, I get junk data. One resource for example returns b'\xd3PS-90AC' whereas another resource, for the same key returns b'PS-90AC' The first value contains a non-ASCII string. Clearly a violation of the spec, but that's unfortunately out of my control. None of us are 100% certain that this really is junk or data which should be kept. The application calling

Powershell byte array to hex

谁说胖子不能爱 提交于 2019-12-23 15:30:07
问题 I have the following byte array that I would like to obtain hex format in order to decrypt an encrypted string using aes-256-ecb. (powershell uses AES encryption if you specify key argument in "ConvertFrom-SecureString" function) In order to check this I verify by using openssl: echo 'mysecretdata' | openssl enc -d -aes-256-ecb -K 303534303438303439303939303438303938303937303435303530303530303937303537303435303439303439303130310a hex string is too long invalid hex key value What am I missing?

Bytes and integers and concatenation and python

被刻印的时光 ゝ 提交于 2019-12-23 12:44:52
问题 I have 2 32bit unsigned integers.. 777007543 and 114997259 and the string of bytes.. 0x47 0x30 0x22 0x2D 0x5A 0x3F 0x47 0x58 How do I get python to give me the concatenation of these 3 such that I have... 0x2E 0x50 0x31 0xB7 0x06 0xDA 0xB8 0x0B 0x47 0x30 0x22 0x2D 0x5A 0x3F 0x47 0x58 I would then run that through an md5 hash and get... 0x30 0x73 0x74 0x33 0x52 0x6C 0x26 0x71 0x2D 0x32 0x5A 0x55 0x5E 0x77 0x65 0x75 If anyone could run that through in python code it would be much appreciated

My byte suddenly becomes a negative number and count down

微笑、不失礼 提交于 2019-12-23 12:17:08
问题 I have some code that increases a byte by 8 bits every time it passes through my loop. It all goes as expected until I hit 120, then my numbers suddenly become negative. Code: byte b = 0; for(int i = 0; i < 0x100; i += 8) { System.out.print(b + " "); b += 8; } Output: 0 8 16 24 32 40 48 56 64 72 80 88 96 104 112 120 -128 -120 -112 -104 -96 -88 -80 -72 -64 -56 -48 -40 -32 -24 -16 -8 What I want to see: 0 8 16 24 32 40 48 56 64 72 80 88 96 104 112 120 128 136 144 152 160 168 176 184 192 200 208

Ruby - How to represent message length as 2 binary bytes

我的梦境 提交于 2019-12-23 10:01:12
问题 I'm using Ruby and I'm communicating with a network endpoint that requires the formatting of a 'header' prior to sending the message itself. The first field in the header must be the message length which is defined as a 2 binary byte message length in network byte order. For example, my message is 1024 in length. How do I represent 1024 as binary two-bytes? 回答1: The standard tools for byte wrangling in Ruby (and Perl and Python and ...) are pack and unpack . Ruby's pack is in Array. You have

How are byte variables stored in memory?

若如初见. 提交于 2019-12-23 09:19:38
问题 I'm reading a book about C# (Pro C# and the .NET 4 Platform by Andrew Troelsen) and I've just read this paragraph: Changing the underlying type of an enumeration can be helpful if you are building a .NET application that will be deployed to a low-memory device (such as a .NET-enabled cell phone or PDA) and need to conserve memory wherever possible. Is it true that bytes use less memory? Aren't they stored on 4 bytes for performance reasons? I remember reading the latter somewhere but I can't

Java IPv6 Address String to Bytes

左心房为你撑大大i 提交于 2019-12-23 08:06:16
问题 How can I convert a String containing the ipv6's machine packet destination to a 16 byte array? I know about getBytes and encodings, but I can't seem to understand which encoding I should use or if I have to convert that String to Hexadecimal or not. String ipv6 = "2001:0DB8:AC10:FE01:0000:0000:0000:0000"; byte[] bytes = ipv6.getBytes(); //must be a 16 byte array An example of what I wanna do, just to exemplify. Obs.: I have to convert the String to a 16 byte array Thanks 回答1: try this