You can split the String into bytes by matching every two hex digits, reverse the returned array, then join the array back into a String: var s = "ded3e8c2e3460a97500c09d752a83c4eb44eda90998e33ce8d346a1174c0b97f"; s.match(/[a-fA-F0-9]{2}/g).reverse().join('') // "7fb9c074116a348dce338e9990da4eb44e3ca852d7090c50970a46e3c2e8d3de" ...
int t194(void) { // imagine you have n pair of char, for simplicity, // here n is 3 (you should recognize them) char pair1[] = "01"; // note: char pair2[] = "8c"; // initialize with 3 char c-style strings char pair3[] = "c7"; // { // let us put these...
To test whether a bit is set in a byte, you use the & operator like this: if ((b & 1) > 0) { // Bit 0 is set } if ((b & 2) > 0) { // Bit 1 is set } if ((b & 4) > 0) {...
The fastest way might be to precompute a table of all the values: final int[] values = new int[256]; for (int i = 0; i < 256; ++i) { values[i] = (i & 0b1100_0000) >> 6 | (i & 0b0011_0000) >> 2 | (i & 0b0000_1100) << 2 | (i...
'>%dH' % 1 is equivalent to '>1H'. >>> '>%dH' % 1 '>1H' '>%dH' % 1 is using old-style string formatting to replace the %d with 1. So the struct format is specifying a big-endian two-byte unsigned short....
javascript,amazon-web-services,amazon-s3,byte,bytearray
Try this var s = "41 57 53 34 2d 48 4d 41 43 2d 53 48 41 32 35 36 0a 32 30 31 35 30 34 32 35 54 31 36 32 33 30 36 5a 0a 32 30 31 35 30 34 32 35 2f 65 75...
This is because you have just copied a function from somewhere for a different filetype and not every filetype has any notion of a "subheader". You only need to check the main header in the case of RAR. I also suggest modifying the naming of the variables, it is quite...
1) Ascii has 128 value, but they are enumerated from 0-127 like most computer arrays. 0 means null. 2) Either the ascii is fit into 8 bit, or you are using the extended 8 bit version. 3) Define your own program that writes to a bytestream, then you can check...
Suppose you are reading the unicode characters from file into a variable called byteString. Then you can do the following: unicode_string = byteString.decode("utf-8") print len(unicode_string) ...
byte[] data = "nibbles".getBytes(StandardCharsets.US_ASCII); for(byte b : data) { int high = (b & 0xf0) >> 4; int low = b & 0xf; System.out.format("%x%n", high); System.out.format("%x%n", low); } ...
python,python-3.x,cryptography,byte,bytestring
Conceptually, a bytes object is a sequence of integers: >>> tuple(b'ciphertext') (99, 105, 112, 104, 101, 114, 116, 101, 120, 116) ... so its constructor will happily accept one: >>> bytes((99, 105, 112, 104, 101, 114, 116, 101, 120, 116)) b'ciphertext' Knowing that, you can change your second line to...
If I recall correctly, the JVM specification mentions that null is not required to have a specific value or representation, so it could be anything. What it typically is, I don't know, but a fair guess is probably 32 or 64 bits of zeros, depending on the JVM version. Edit:...
// ... Stream webStream = webResponse.GetResponseStream(); using (var stream = File.Create(@"C:\file.pdf")) { webStream.CopyTo(stream); } Why don't you do it simply with WebClient like this? using System.Net; using (WebClient webClient = new WebClient()) { webClient.DownloadFile(URL, @"C:\file.pdf"); } ...
java,byte,data-type-conversion
Actually you are trying to convert an int to byte here: Byte byt=new Byte(00000001); If you want to call the function you could do this, using a cast: Byte byt=new Byte((byte)1); Hope it helps....
objective-c,arrays,swift,byte,nsdata
Your biggest problem is that the type of your myCertificate array is Int not Int8. Here is something that is working for me. Note I reconstructed the array from the NSData object to see if everything came out ok. let myCertificate = Array<Int8>(arrayLiteral: 103, 92, -99, 33, 72, 48, 119,...
Interesting, not much is out there for PHP. There seems to be a promising post, but unfortunately the accepted answer gives incorrect results in Your case. So here's a revised version of Adam's solution rewritten in PHP. /** * Translates a sequence of UTF-8 bytes to their equivalent unicode code...
A nice way to achieve this would be to use the combination of struct and union. With a union, you can access the same memory in two different ways. For example: union gpio_type { uint8_t data; struct raw { unsigned int b0 :1; unsigned int b1 :1; unsigned int b2...
c#,bit-manipulation,byte,bytearray,implicit-conversion
result is already a byte[], so do this instead: BitArray b = new BitArray(result); The part that's actually causing the problem is this: new byte[] { result } The reason for this is because the array initializer needs to take expressions that are compatible with the element type of the...
c#,hex,type-conversion,byte,int64
If you simply want to get all of the bytes from your Int64 value, you can do that like this: Int64 myValueFromDB = 13; var asBytes = BitConverter.GetBytes(myValueFromDB); To check if this produces what you expect, you can print this result like this: Console.WriteLine("{{{0}}}", string.Join(",", asBytes.Select(x => "0x" + x.ToString("X2"))));...
You can get rid of that compiler error by just casting the value to byte: myArray.Add((byte)Convert.ToInt32(Line)); However, when you run that code you will get a different error: Unhandled Exception: System.FormatException: Input string was not in a correct format. That's because the Convert.ToInt32 method doesn't parse hexadecimal numbers out of...
java,integer,byte,short,typeconverter
If the original length from entry.getKey().length is greater than 255, then the actual length information is lost. However, if the original length was between 128 and 255, then it can be retrieved. The narrowing conversion of casting to byte keeps only the least significant 8 bits, but the 8th bit...
You should use the getId method of your Message enum : message[0] = ByteMessage.M.ACK.getId(); Each constant in an enum is an instance of the enum. Just like classes, an instance of an enum can have data. In your specific case, each enum constant has an id which is initialized when...
You can create a simple convenience function using the struct module to convert integer addresses into the binary string format that the xbee module wants (which appears from your example to be big-endian unsigned short): >>> import struct >>> def make_address(addr): ... return struct.pack(">H", addr) ... >>> make_address(1) '\x00\x01' ...
java,javascript,node.js,byte,bytearray
If I correctly understand your question, you can use Buffer to get file contents, then read the bytes from it into your array. Java byte type is a signed 8-bit integer, the equivalent in Node.js Buffer is buf.readInt8(). So you can read the required amount of bytes from Buffer into...
You'd normally have the shell formulate the exact bytes, but since you cannot pass in NUL bytes as arguments asking users to pass in escape sequences is a reasonable work-around. However, the shell is not going to interpret Python byte string literal notation. In this case, I'd ask the user...
The order of bits looks reversed, but once you realize that entries in bit array are numbered from least significant to most significant, it all makes sense: 00001010 Index Value -------- ----- ----- |||||||| |||||||+----- 0 false ||||||+------ 1 true |||||+------- 2 false ||||+-------- 3 true |||+----------4 false ||+-----------5 false...
1 + "test" = "est" // 1 offset from test So you are getting the correct answer. +---+---+---+---+---+ | t | e | s | t | \0| +---+---+---+---+---+ +0 +1 +2 +3 +4 What you want is possibly: std::string test; test += x; test += "test"; ...
java,string,unicode,byte,bytearray
For Unicode characters, you can specify the encoding in the call to getBytes: byte arr[] = S.getBytes("UTF8"); As far as why you are getting 63 as a result, the call to getBytes without a parameter uses your platform's default encoding. The character \u9999 cannot be properly represented in your default...
An integer is comprised of 4 bytes, so your byteArr needs to have 4 elements, not 2: byte[] byteArr = new byte[4]; ...
You could start by implementing an IComparer<IList<byte>>. E.g. (omitting null handling for brevity): public class ByteListComparer : IComparer<IList<byte>> { public int Compare(IList<byte> x, IList<byte> y) { int result; for(int index = 0; index<Min(x.Count, y.Count); index++) { result = x[index].CompareTo(y[index]); if (result != 0) return result; } return x.Count.CompareTo(y.Count); } }...
You can just bitwise OR them together, shifting one of the nibbles using <<: byte firstByte = (byte)(byteArray[0] | byteArray[1] << 4); byte secondByte = (byte)(byteArray[2] | byteArray[3] << 4); You didn't specify the order in which to combine the nibbles, so you might want this: byte firstByte = (byte)(byteArray[1]...
It's not that hard. Of course there's a system to it - else no program could print or edit names like Ñáñez... The upper bits in each byte indicate what is the status of that byte: 1) if bit 7 is 0, then it's just ASCII (*0*1110111 = w) 2)...
lets call a byte b, if you set b to 0, you end up with (binary) 0000 0000 (space for readability) Now we want to pack the different parts into this byte engine_on 0-1 1 gear_pos 0-4 3 key_pos 0-2 2 brake1 0-1 1 brake2 0-1 1 brake2 is simple....
I think your code is too complicated. You could find the absolute position of the difference and then divide it by the size of the array type. Example code: private int diffpos(byte[] a, byte[] b, int typeLenght){ if (a.length == b.length) { for (int i = 0; i < a.length;...
The strings don't match because they shouldn't. The operation printBase64Binary turns an arbitrary byte stream into a sequence of printable ASCII characters. However, this sequence won't just contain any old collection of printable ASCII characters - if a string is a valid Base64 translation of some byte sequence then there...
If I'm understanding your question, before you perform any calculations you need to AND (&) your bytes against 255, so you'll be dealing with values from 0 to 255 instead of -128 to 127. When you assign a value higher than 127 to a byte it overflows, so 128 as...
You could use ord to extract each character's numeric value, then combine them with simple arithmetic. >>> a = '\x02' >>> b = '\x00' >>> c = ord(a)*256 + ord(b) >>> c == 0x0200 True >>> print hex(c) 0x200 ...
Byte has 8bits thus values ranges from <-128,127> or <0x00,0xFF> so you can not encode 0xFFFF if it is representing integer (65535) into byte cos it would not fit. However if it is representing Short 0xFFFF means -1 (if signed) which is convertible into byte. The code would look like...
What you are failing to see is that a+b is a run-time operation whereas byte b = (int)8; is a compile-time operation. SO, during compile-time, the compiler knows that the constant 8 can be fit in a byte. So, the explicit conversion to (int) is ignored. The byte code will...
arrays,swift,type-conversion,byte,bit
A possible solution is to enumerate all bits in the array and for all "One" bits set the corresponding bit in the UInt8 array: func bitsToBytes(bits: [Bit]) -> [UInt8] { let numBits = bits.count let numBytes = (numBits + 7)/8 var bytes = [UInt8](count : numBytes, repeatedValue : 0) for...
Despite being an ASCII (within range of 0 to 256), why those 3 extended characters take 2 bytes of space? If you define 'being ASCII' as containing only bytes in the range [0, 256), then all data is ASCII: [0, 256) is the same as the range a byte...
java,byte,bytearray,thermal-printer,receipt
I have no idea if this will improve your printing speed, but in answer to your question about reducing the number of "print jobs", you could write all the bytes to a stream first, then send the whole stream to a single print job. I've attempted to convert your code...
java,io,integer,byte,dataoutputstream
Use: dataOutputStream.writeShort(i1); to write i1 as a short (which is 2 bytes). Similarly, there is writeInt (4 bytes) and writeLong (8 bytes). DataOutputStream has a method to write each of Java's primitive types....
byte[] and String should be kept apart. The main error is that a random sequence of bytes (the encrypted text) might easily be incorrect UTF-8. UTF-8 is a multi-byte format, where high bits mark a multi-byte sequence in a specified way, 10xxxxxx being a continuation byte for instance. However to...
java,stream,byte,inputstream,outputstream
Invalid code. See the Javadoc. InputStream.read(byte[] [,...]) isn't obliged to transfer more than one byte, and it is never valid to call it without storing the result into a variable. If you're expecting more than one byte, you have to loop, or use DataInputStream.readFully(). The canonical way to copy streams...
Why is the key-length 26? C#-strings is in unicode, so you can write all characters out there eg. Chinese, Japanese, etc. etc. That takes two bytes. 13*2=26. Is your wep-key 128 bits You've got a key for 128 bit wep-protocoll which is using 104 bit keys. (fun times) Wiki on...
You can do it simply like that: char bytes[] = {0x8A, 0x04, 0x00, 0x00}; int* p_int = (int*)bytes; // Unsafe version ,doesn't take into account endianness int num2 = bytes[0] | ( (int)bytes[1] << 8 ) | ( (int)bytes[2] << 16 ) | ( (int)bytes[3] << 24 ); // Safe...
Shift the value x bits to the right and then use AND to restrict the number of bits you use. ie: (n >> 8) & 0xff or (n >> 16) & 0xff.
java,arrays,byte,raster,image-rotation
After some work, I came up with this: public class ImageRotation { public static void main(String[] args) throws IOException { BufferedImage img = ImageIO.read( ImageRotation.class .getResourceAsStream("Capture.PNG")); JPanel pane = new JPanel(); pane.setLayout(new BorderLayout()); pane.add( new JLabel("Original", new ImageIcon(img), JLabel.CENTER), BorderLayout.WEST); pane.add( new JLabel("Rotated", new ImageIcon(rotateClockwise(img)), JLabel.CENTER), BorderLayout.EAST); JFrame frame =...
In case you don't realize: 16 bytes is the size of a Guid or the size of a standard cryptographic key size. There are so many combinations that you cannot enumerate even a fraction. Maybe you can enumerate the last 8 bytes if you parallelize across 1000 machines and wait...
java,python,struct,byte,unpack
This is how I handled to do that, I don't think/know if its the best way to do it but after many searchs I made my own, I might be making an actual and complete/clean api for doing that. if I do so I will post it here x stands...
The problem is in your bracketing for the first character in the Java code. Here's your code: GetHexVal((char)(hex.charAt(i << 1) << 4)) That's getting the character, shifting that, then calling GetHexVal. You want to shift the result instead: // Unnecessary cast removed GetHexVal(hex.charAt(i << 1)) << 4 This would have...
No. JSON should be a String, since it has an encoding and a meaning. byte[] is generally a physical, uninterpreted sequence of bytes; String is a sequence of characters.
Here's one way to do it: h := (uint32)(((fh.year*100+fh.month)*100+fh.day)*100 + fh.h) a := (*[4]byte)(unsafe.Pointer(&h))[:] Here's a breakdown of what's going on. The code (*[4]byte)(unsafe.Pointer(&h)) converts the uint32 pointer to a [4]byte pointer. The [:] at the end creates a slice on the [4]byte. The code in the question interprets the...
Using == for functions only checks if they reference to the same function, which is not what you expected. This task is rather difficult, if not impossible at all. For really simple cases, here's an idea: function f(x) return x + 1 end local g = function(y) return y +...
bgtz doesn't place the next PC address into the return address register, so jr $ra won't return to the instruction after the branching statement. You can either use bgtzal (branch if greater than zero and link), which will give you the behaviour you are looking for, or else you can...
java,byte,bytearray,bytebuffer
When using ByteBuffer there is a difference between putting and getting values from the buffer. When bytes are put on the buffer they get added at the current position. If the limit is reached then the buffer is full. So position() shows the amount of data in the buffer and...
file,type-conversion,byte,fat16
You are not reading the values properly. Most of them are longer than 1 byte. From the spec you can obtain the length and meaning of every attributes in the boot sector: Offset Size (bytes) Description 0000h 3 Code to jump to the bootstrap code. 0003h 8 Oem ID -...
I think you mean bits, not bytes. String bitstr = "00000011"; byte convbyte = Byte.parseByte(bitstr, 2); The , 2 tells it that you're parsing a binary (base 2) string; the default would be decimal (base 10)....
caching,byte,system,memory-address
Before your answer let's look at some calculations(see log as log to the base 2): i) Number of Sets= 32/2 =16. Hence number of bits required to point address a set= log 16=4. ii) Number of bits to be left aside as offset within a line= log 8 =3. 8...
ruby,integer,bit-manipulation,byte
Here's something that may help you: def rbit(n) r = 0 8.times{|i| r = r * 2 + n[i] } r end Credit Reverse bit order of 32 bit integers by mark-hubbart Or if you prefer bit operators, something like this: def rbit(n) (((n & 0x01) << 7) |((n &...
vb.net,memory,byte,integer-overflow
This is not the proper way of adding an offset to an IntPtr. It provides the Add method for doing that. I am assuming that you are already marshaling the BaseAddress field of the MEMORY_BASIC_INFORMATION structure as an IntPtr. So you should change your code to Addy = IntPtr.Add(MemInfo.BaseAddress, MemInfo.RegionSize);...
.net,vb.net,file,byte,filestream
You need to calculate the right amount to read before actually reading. Right now, you always read chunkSize bytes but you are sometimes discarding the tail of that buffer. I think the intention is that tmpBufferLength has the correct buffer length. Assuming that works out (which I am too lazy...
static byte[] ROR_ByteArray(byte[] arr, int nShift) { return ROL_ByteArray(arr, arr.Length*8-nShift); } ...
You can extract the data using subdataWithRange(): let firstData1 = mutableData.subdataWithRange(NSMakeRange(sizeof(Int), length)) if let firstString1 = NSString(data: firstData1, encoding: NSUTF8StringEncoding) as? String { println(firstString1) } else { // bad encoding } Your solution var data = NSData() mutableData.getBytes(&data, range: NSMakeRange(sizeof(Int), length)) does not work and crashes because NSData is a...
python,python-3.x,byte,bytearray
Just call the bytes constructor. As the docs say: … constructor arguments are interpreted as for bytearray(). And if you follow that link: If it is an iterable, it must be an iterable of integers in the range 0 <= x < 256, which are used as the initial contents...
When you do an UPDATE like the following: UPDATE device SET Area = " + btn + " WHERE Name = 1 you need to send information about the table, column, value and where restriction. However, when you perform an INSERT like this: INSERT INTO device (Area) VALUES (...) you...
Converting types in C# is relatively trivial: File.ReadAllBytes(filePathHere).Select(b=>(sbyte)b).ToArray(); As a side note, files are supposed to be made of unsigned bytes, so there's no need for sarcasm ("C# thinks its being helpful"). It's just that Java doesn't have proper data types to deal with it. ...
You can't just "not read" bytes from a socket. So, read the entire string and select the characters you want as explained in Extract only right most n letters from a string: string lastTwo = input.Substring(input.Length - 2); But as Marc points out in the comments, your reading code won't...
You have to read the file, do your stuffs (decrypt?), then write the content to a new file and run it. Something like that (you can embed your file in the project resources if you want): // Read file content from project resources byte[] fileContent = MyProject.Properties.Resources.MyFile; // <Do your...
Since sine has a limited range [-1.0, 1.0], you can map the value from that range to the range of 16-bit integers [-32768, 32767]. short sample_short = SHORT_MAX * sample; There will be some round-off error, but that's necessary to squeeze the values into the less precise data type. The...
java,type-conversion,byte,bytearray,bucket
This would be covered high-level by a ByteBuffer. short loc = (short) writeLocation; byte[] bucket = ... int idex = bucket.length - 2; ByteBuffer buf = ByteBuffer.wrap(bucket); buf.order(ByteOrder.LITTLE__ENDIAN); // Optional buf.putShort(index, loc); writeLocation = buf.getShort(index); The order can be specified, or left to the default (BIG_ENDIAN). The ByteBuffer wraps the...
The character you are getting there is not a "normal" space. It's a no-break space. The same character that in HTML would be described with . Its unicode value is '\u00A0'. Its UTF-8 representation is C2 A0, which is what you are getting in your byte array. I believe if...
This is the right way to open a file from a byte array: var bytes = . . .; using (var file = new org.pdfclown.files.File(new org.pdfclown.bytes.Buffer(bytes))) { } If you check out PDF Clown from its repository (version 0.1.2.1 or later) or download the next release, you can even use...
Try this ByteBuffer buffer = ByteBuffer.allocate(2); buffer.putShort(short_value); return buffer.array(); ...
c#,byte,filestream,streamreader,readline
You can read all bytes and iterate through buffer searching for line endings. When you find line endings convert textparts with string text = Encoding.UTF8.GetString(buffer, start_len, end_len); p.s. be sure to use exact encoding... UTF8 is an example......
In your Junit test you are comparing object references instead of object content. What perhaps you wanted to achieve is to compare the content of byte arrays. You can use Assert.assertArrayEquals by importing import org.junit.Assert; E.g. Assert.assertArrayEquals(bytes, FileConverter.ToBytes(pathName));...
java,type-conversion,bit-manipulation,byte,long-integer
java's byte type is signed, so 0xff (255) == -1, during extending from byte to int/long - signed value is preserved, so if you just have code: final byte a = (byte)0xff; final long b = a; System.out.println(b); // output here is -1, not 255 so, here comes one trick:...
java,string,unicode,utf-8,byte
Not all sequences of bytes are valid in UTF-8. UTF-8 is a smart scheme with a variable number of bytes per code point, the form of every byte indicating how many other bytes follow for the same code point. Refer to this table: Bytes 1 (hex 0x01, binary 00000001) and...
byte is an 8-bit unsigned integer that will implicitly get upcast to an int when needed. Maybe I'm under-thinking things, but what's wrong with the obvious and efficient: byte[] octets = {25, 10, 13, 04, 16, 26} //day month year hour minute second DateTime date = new DateTime( 2000 +...
What about that? byte[] byteArray = new byte[2]; byteArray[0] = (byte)byteIntArray[0]; byteArray[1] = (byte)byteIntArray[1]; String specialChar = new String(byteArray); Note that String.getBytes() uses your local platform encoding to convert the string into a byte array. So the resulting byte array depends on your individual system settings. If you want your...
+ dataWithBytes:length:: Creates and returns a data object containing a given number of bytes copied from a given buffer. + dataWithBytesNoCopy:length:: Creates and returns a data object that holds length bytes from the buffer bytes. dataWithBytes makes a copy of the buffer for the data, while the NoCopy version does...
I am assuming your pointer refers to 20 bytes, for the 160 bit value. (An alternative may be text characters representing hex values for the same 160 bit meaning, but occupying more characters) You can declare a class for the data, and implement a method to increment the low order...
Just write the image_string, you don't need bytes as image_string is already a bytes object as you open using 'rb': dest_image.write(image_string) with open(image_path,'rb') as image_file: image_string = image_file.read() with open(new_image_path,'wb') as dest_image: dest_image.write(image_string) print(type(image_string)) <class 'bytes'> ...
b >> 1 returns an int which can't be automatically cast to byte. You can just add a cast: .map(b -> (byte) (b >> 1)) ...
Guessed on your output image it's a charset problem. following snippet return the same byte values for your input string. String testString = "TEST for stackoverflow"; byte[] bytes = testString.getBytes(StandardCharsets.UTF_8); System.out.println("bytes = " + Arrays.toString(bytes)); bytes = testString.getBytes(StandardCharsets.ISO_8859_1); System.out.println("bytes = " + Arrays.toString(bytes)); output bytes = [84, 69, 83, 84,...
In this case char comes after int and no need to add padding bytes, it means sizeof(A) = 5 byte, but in this case I also get the 8 byte result. Why ? First you need to understand why padding is needed? Wiki says that: Data structure alignment is...
vb.net,type-conversion,byte,bytearray
As said in my comment from above, your not casting your property in the memory stream you have created. Also if plr.PlayerImage is not defined as Byte() you will get an exception. Here's what it may look like... Public Property PlayerImage As Byte() Here's what you currently have... Dim ms...
It seems that auto-casting to byte is not done when the value approaches the capacity of a byte. No, it happens when the value is out of range. A byte in Java is in the range [-128, 127]. So 0xcc is out of range, for example... although this has...
The literal 00000011 is an octal integer literal in Java, in this case octal 11, which is equivalent to 9 in decimal. Use 0b00000011 (with a 0b instead of 0 prefix) to make a binary literal.
I'm not exactly sure what are you up to, but fread will read a character as string. If you want to display its byte value (ASCII) you can use ord and optionally dechex: while ($char = fread($stream, 1)){ printf("Byte value of '%s' is %d (%s hex)\n", $char, ord($char), dechex(ord($char))); }...