FAQ Database Discussion Community


Possible lossy conversion from int to byte Java

java,byte,data-type-conversion
Java neophyte here. We are coding something to just create, initialize, and print each of the primitive data types in Java. We can create and reassign values fine, but printing the values is not working. We are successful for printing the int type, but we get the error "Possible lossy...

Converting from byte array to bitarray

c#,arrays,byte,bitarray
I'm learning c# and working with files and types. Problem is that I want to convert byte[] to BitArray, here's screenshot what I get: On the left is my byte[] B and on the right is BitArray of it. What I want to achieve is BitArray to be 00001010 for...

ByteBuffer from short to byte[]

android,libgdx,byte
I let the user record a short snippet of sound. It´s stored as short[] final int samples = 44100; boolean isMono = true; final short[] data = new short[samples * 5]; final AudioRecorder recorder = Gdx.audio.newAudioRecorder(samples, isMono); final AudioDevice player = Gdx.audio.newAudioDevice(samples, isMono); ByteBuffer buffer; start to record: public void...

What is the proper way to represent an audio sample in two bytes?

arrays,file,audio,byte
I'm working on an application that generates a sequence of numbers representing a sine wave, and saves the sine wave in a .wav file to be played as audio. The following line of code generates the value of a single sample in the audio wave: double sample = Math.Sin(2.0 *...

C++ How to create byte[] array from file (I don't mean reading file byte by byte)?

c++,file,visual-c++,byte
I have a problem I neither can solve on my own nor find answer anywhere. I have a file contains such a string: 01000000d08c9ddf0115d1118c7a00c04 I would like to read the file in the way, that I would do manually like that: char fromFile[] = "\x01\x00\x00\x00\xd0\x8c\x9d\xdf\x011\x5d\x11\x18\xc7\xa0\x0c\x04"; I would really appreciate any...

What happens under the hood when bytes converted to String in Java?

java,string,unicode,utf-8,byte
I have a problem when trying to convert bytes to String in Java, with code like: byte[] bytes = {1, 2, -3}; byte[] transferred = new String(bytes, Charsets.UTF_8).getBytes(Charsets.UTF_8); and the original bytes are not the same as the transferred bytes, which are respectively [1, 2, -3] [1, 2, -17, -65,...

Calculate bytes of the unicode character in python

python,unicode,byte
I'm writing a Python script to read Unicode characters from a file and insert them into a database. I can only insert 30 bytes of each string. How do I calculate the size of the string in bytes before I insert into the database?

Do the common terminal operations not work with Stream?

java,byte,java-8,java-stream
I have a simple Stream that is meant to work on Bytes: List<Byte> byteList = Arrays.stream(new Byte[]{0x1, 0x2, 0x3, 0x4}) .map(b -> b >> 1) .collect(Collectors.toList()); The compiler gives: Error: incompatible types: inference variable T has incompatible bounds equality constraints: java.lang.Byte lower bounds: java.lang.Integer And this also does not work:...

Understanding struct.unpack python

python,byte,unpack
test = struct.unpack('>%dH' % 1, '\x00\x44') Is confusing me. I thought it means take the first 8 bytes and treat them as a double then take the next two and treat them as a short, and do all of that one time. But it means something else and I can't...

how to convert python struct.unpack to java

java,python,struct,byte,unpack
I am trying to find java equivalent for python's struct.unpack('hccccc',raw) https://docs.python.org/2/library/struct.html How can I do this in a clean way?...

Java byte array doesn't convert back to its original string when using DatatypeConverter

java,arrays,byte,java-8
I am using DatatypeConverter to convert my strings to byte arrays and vice-versa, however when going from a byte array back to a string it doesnt report the same value as initially given. This is a minimal example that runs on ideone /* package whatever; // don't place package name!...

GPIO value to Byte

byte,microcontroller,gpio
I wanna to make a simple converter. It's simple theoritically, but I can't figure out how to achieve it. So, here is what I wanna do: First I will read my GPIO value from the Microcontroller, with quantity of 8. Now, I have 8 byte of GPIO value from GPIO...

How to Convert Binary to Hex

binary,hex,byte,bits
So I have a binary number but there's only 11 bits. The number: 10111101110 I need to convert this to hexadecimal. I divide into three parts: 101 1110 1110 I know the last two parts are EE The part with three bits is catching me. If i add a zero...

Trouble to save PDF file from a java web service using C#

java,c#,arrays,pdf,byte
I'm retrieving a PDF file from a web server java, returning a byte array. Need save the PDF on the local machine using C #, but the file is saved completely in blank, I think it is because of the byte array format is different. Here is my code: StreamReader...

How to find out total number of bytes stored in ByteBuffer?

java,byte,bytearray,bytebuffer
I am trying to extract total number of bytes I have stored in my ByteBuffer data_record_value. Below is how we representdata_record_value as one Byte Array and then write to our database from Java code. Offset Length (in bytes) Purpose 0 2 - clientId byte array 2 8 - value of...

Java byteArray equivalent in JavaScript

java,javascript,node.js,byte,bytearray
I am trying to determine what encoding scheme will give me the numbers -1 or -40 (the starting numbers for the file) for a jpeg file type. A rest api I'm working on is expecting a byte array that looks like [-1, 94, 43, 34, etc]. In node.js I can...

In Java, byte[] vs string as a method parameter have any pros/cons?

java,string,parameters,byte
I have a tab delimited file and I need to pass it around. I will be using BufferedReader to read lines. In that case does passing it as a byte[] vs String have any advantages and disadvantages. If the file contains json data, would passing around as byte[] vs string...

How to increment the value of an unsigned char * (C)

c++,c,openssl,byte,sha1
I have a value stored as an unsigned char * (in C). This holds the SHA1 hash of a string. My goal is to cover the SHA1 key space. Since I'm using <openssl/evp.h> to generate the hashes, I end up with an unsigned char* holding the SHA1 value. Now I...

Add hexadecimal from file to List

c#,arrays,hex,byte
I'm trying to make a List<byte> from a file that contains string (Hexadecimal) . the definition is : List<byte> myArray = new List<byte>(); if I want to add my information directly I use something like this : myArray.Add(0xb8); Note : Without any quotation or double-quotation . The problem is when...

How does this reverseBytes method work?

c,byte,bit,bit-shift
I was looking at this function online and am wondering how it works: /* * reverseBytes - reverse bytes * Example: reverseBytes(0x12345678) = 0x78563412 * Legal ops: ! ~ & ^ | + << >> */ int reverseBytes(int x) { int newbyte0 = (x >> 24) & 0xff; int newbyte1...

Reading necessary bytes

c#,string,byte,elm327
is it possible to read only last two bytes from a string. For example I receive 41 0C 34 from a stream socket, and I only need 34. In what way I can do this. Here is my code: public string ReadSensor(ISensor sensor) { if (ConnectedPort == null) return null;...

Escaped string of bytes to bytestring

python,string,byte
I'm new to Python and I need to read bytestring from a command line argument. I'm using Python 3.4. At the moment, I'm using argparse to parse the arguments, with this configuration for the data: parser.add_argument("-d", "--data", default=b'\0') When I call my program with -d argument (e.g. python myprogram.py -d...

readbytes of a file and running it

c#,.net,vb.net,byte
I have 2 .net files ! once with c#.net and another one with vb.net :) Now I want read the bytes of it and running it :) Dim mybyte As Byte() = System.IO.File.ReadAllBytes("E:\Projects\Expired.exe") System.Reflection.Assembly.load(mybyte) Could not load file or assembly '8192 bytes loaded from mybyte ...

C# How to extract bytes from byte array? With known starting byte

c#,arrays,byte,bytearray
I need to get specific bytes from a byte array. I know the content of the first byte I want and I need x bytes after that. For example, I have byte [] readbuffer { 0, 1, 2, 0x55, 3, 4, 5, 6}; byte [] results = new byte[30]; and...

Convert Hex To Byte Array in Java gives different results from C#.NET [port from C# to Java]

java,c#,hex,byte
I am trying to convert a small piece of code to Java from C#. [I think don't have to say I'm a noob. :P] The two codes below returns differently I don't understand why. Thanks for any help. P.S.: I've checked the question here but the answer doesn't fix my...

Convert int array of byte to String in JAVA

java,string,byte
i have following problem: i have array of 2 int - its char ř how can i convert this array to string or char? real values in array are: [-59, -103] ř->[-59, -103]->ř Thank you. EDIT: String specialChar = "ř"; System.out.println(specialChar); byte[] tmp = specialChar.getBytes(); System.out.println(Arrays.toString(tmp)); //[-59, -103] int[] byteIntArray...

Swift. How to write bytes from NSData into another NSData?

ios,swift,byte,nsdata
I'm trying to concatenate two NSData objects into one NSMutableData, and than get them back. For now i'm trying to do it in such way: Get length of first object. Write into NSMutableData in such order: first object length, first object, second object. Code looks like: let firstString = "first_string";...

Why padding are added, if char comes after int?

c,struct,byte,padding,sizeof
For example, there is a structure struct A { char a; int i; }; In this case, we have a[1 byte] + padding[3 byte] + int[4 byte] = 8. Now let's make little update into struct above, struct A { int i; char a; }; In this case char comes...

C# Byte Array conversion to VB.Net

c#,arrays,vb.net,byte
As per my last question I'm borrowing some code from the Opus project to integrate into VB.Net software Any help translating this appreciated... byte[] buff = _encoder.Encode(segment, segment.Length, out len); Which I've translated to: Dim buff(wavEnc.Encode(segment, segment.Length, len)) As Byte Which is throwing a Value of type '1-dimensional array of...

Byte testing c#

c#,byte
I have a data acquisition module. It return a byte for each bit is 1. Example : - Byte : 9 - 0000 1001 And I would like to know how see if each bit is 1. Someone tell me to do " 9 & 1 " in order to...

How can I convert bytes received in an AWS error message into something readable in Javascript?

javascript,amazon-web-services,amazon-s3,byte,bytearray
I'm trying to debug an wrong signature calculation when accessing Amazon S3 via JavaScript. AWS returns an XML document which includes: <StringToSignBytes>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...

Add byte array to another byte array at specific position java

java,byte
I want to create a byte array of size 512 bytes. For the first 100 bytes I want to reserve it for filename, for the next 412 bytes I want to use it to store data from the file itself. Something like this : |----100byte for file name ----||------------412 byte...

How can I write the “word” representation of an integer to a file in Java?

java,io,integer,byte,dataoutputstream
Here is a sample code: File x = new File("garbage.byte"); x.createNewFile(); int i1 = 5; DataOutputStream dataOutputStream = new DataOutputStream(new FileOutputStream(x)); dataOutputStream.write(i1); dataOutputStream.flush(); dataOutputStream.close(); When I open the file garbage.byte in a hex viewer I will see: 00000101 which is ok. My question is, what if I have an integer...

Need help to work with characters longer than 2 or more bytes in Python

python,binary,byte,bits
I'm learning about bits and bytes in python by writing a small program that converts strings to binary and back to string again. Temporarily I only have a function that converts to binary. string = 'word' for c in word: convertToBinary(c) #Function that converts to binary Output: 01110111 01101111 01110010...

Initialize java byte array: possible loss of precision

java,byte
I am initializing a byte[] in Java, using hexadecimal or binary notation. It seems that auto-casting to byte is not done when the value approaches the capacity of a byte. Solution is explicit cast to byte. $ javac bitsandbytes/ByteBufferTest.java bitsandbytes/ByteBufferTest.java:9: error: possible loss of precision static byte[] byteArray = {...

How to replace bytes in VB.NET?

vb.net,replace,hex,byte
I have two strings: Dim Original_Hex_Bytes as string = "616572646E61" Dim Patched_Hex_Bytes as string = "616E64726561" Then I have a binary file and I need to search for the Original_Hex_Bytes and replace them with Patched_Hex_Bytes; I don't konw the offset where begin to write new bytes :( How can I...

Arithmetic operation resulted in an overflow Error

vb.net,memory,byte,integer-overflow
I am getting this error Arithmetic operation resulted in an overflow I have already looked it up on stackoverflow. still couldn't find a solution. My code Private m_MemReg As List(Of MEMORY_BASIC_INFORMATION) Public Sub MemInfo(ByVal pHandle As IntPtr) Dim Addy As New IntPtr() While True Dim MemInfo As New MEMORY_BASIC_INFORMATION() Dim...

default format for byte data type

java,byte
I was just doing a task about retrieving the bits from a byte. When I was just retrieving a byte I was getting wrong results. For a byte byte b = (byte) 00000011; the retrieved bits were in the order 00001001 After observation I found that the compiler interprets the...

char concat to string returns wrong length

c++,string,sockets,byte
simple c++ program that adds a char byte to a string. The resulting length is wrong in the output. #include <iostream> #include <string> int main(){ char x = 0x01; std::string test; test = x+"test"; std::cout << "length: " << test.length() << std::endl; std::cout << "test: " << test << std::endl;...

Byte conversion back to Image

vb.net,type-conversion,byte,bytearray
I'm trying to convert the bytes in plr.PlayerImage back into an image for the picturebox. However, Method 1 returns the error "Value of type Byte cannot be converted to 1-dimensional array of Byte" on plr.PlayerImage. Method 2 provides the error message "Conversion from type Byte() to type Byte is not...

Best way to read single byte from array of bytes

c#,arrays,byte
I have array of bytes and I want to read those bytes one by one and convert it into int. I am getting date in byte of array so need to create DataTime object from that. I am using following code. What should the best approach for the same from...

Xocde - What is the difference of 'dataWithBytesNoCopy' and 'dataWithBytes'?

ios,byte,nsdata
What is the difference of + (instancetype)dataWithBytes:(const void *)bytes length:(NSUInteger)length; and + (instancetype)dataWithBytesNoCopy:(void *)bytes length:(NSUInteger)length;' Also, + (instancetype)dataWithBytesNoCopy:(void *)bytes length:(NSUInteger)length freeWhenDone:(BOOL)b; if b == YES, it will free the bytes automatically after converted to data ? I am working on an app and almost finished it. But the last problem...

Checking byte with bitwise operators

c,bit-manipulation,byte,bit
I could use this: unsigned long alpha = 140 | 130 << 8 | 255 << 16; to set 140 to the first byte of alpha, 130 to the second and 255 as 3rd. How do I do the opposite (i.e checking a specific byte of alpha) ? alpha &...

How to convert negative byte value to either short or integer?

java,integer,byte,short,typeconverter
We have a file which contains byte array in particular format like header and then followed by data. This file is generated by another java program and then we are reading that same file through another java program in the same format in which it was written. The program which...

How to split byte array and assign to a byte variable?

c#,arrays,methods,split,byte
In my C# Application, I have a byte array as follows. byte[] byteArray = {0x2, 0x2, 0x6, 0x6}; I need to split the first two elements i.e 0x2 and 0x2 and assign it to a byte variable. Similarly last two elements should be assigned to another byte variable. i.e byte...

How many bytes a null object? [duplicate]

java,object,memory,byte
This question already has an answer here: Java - Does null variable require space in memory 4 answers When we have a reference variable e.g. to simplify it Integer i we can assume that the size of i is approximately 16 bytes overhead + 4 bytes for the actual...

Sorting list of list of bytes or list of byte arrays

c#,arrays,linq,sorting,byte
LINQ has great OrderBy functionality with ThenBy and so on, but how could I make this work on List<List<byte>> to sort by 1st column, then by 2nd and so on. List of list of bytes: [0] = {0, 1, 2, 3, 4} [1] = {0, 0, 2, 4, 1} [2]...

Reading a FAT16 file system

file,type-conversion,byte,fat16
I am trying to read a FAT16 file system to gain information about it like number of sectors, clusters, bytespersector etc... I am trying to read it like this: FILE *floppy; unsigned char bootDisk[512]; floppy = fopen(name, "r"); fread(bootDisk, 1, 512, floppy); int i; for (i = 0; i <...

how i can rotate image by array of byte in java?

java,arrays,byte,raster,image-rotation
I have array of byte for image , and I want to rotate image by this array , this is my code : BufferedImage img = ImageUtil.load(inputImagePath); WritableRaster raster = img .getRaster(); DataBufferByte data = (DataBufferByte) raster.getDataBuffer(); byte [] pixel = data.getData(); how i can do this ? , thanks...

Why does updating a MySQL table through MS Access take up more than inserting a row?

mysql,ms-access,byte
I would think it would take less because here is my command: UPDATE device SET Area = " + btn + " WHERE Name = 1 For some reason, this is 2160 bytes while inserting only requires 1500 bytes, even when I am inserting more data than I am updating....

How to convert Bytes(UTF-8) to Unicode in php?

php,unicode,utf-8,byte,emoji
How can i convert \xF0\x9F\x98\x83 to \u1F603 in php? PS: it's a Emoji -> 😃, i need Unicode to use Twemoji....

Getting the value of an enum field

java,enums,byte
I have an enumeration of byte values: public class ByteMessage { public enum Messages { ACK(0x01), CHAT(0x02), TURN(0x02), WAITING(0x03), REMATCH(0x04), DOUBLE(0x05), LOADREQUEST(0x06), LOADCOMPLETE(0x07), ROLL(0x08), DBLACCEPTORDECLINE(0x09), DBLRECV(0x0A), ALERTPEERNOPOSSIBLES(0x0B), UPDATEDIES(0x0C), SETTURN(0x0D), SETFIRSTROLL(0x0E), CALCPOSSIBLEINDEXES(0x0F), LOADGAMEREQUEST(0x10), LOADGAMECOMPLETE(0x11), PUSHSTATUSTEXT(0x12), ISDOUBLESOWNER(0x13); private final byte id; Messages(int id) { this.id = (byte) id; } public byte getId()...

Can't read bytes from file PHP

php,file-io,byte
I have a problem, even I use "rb" in fopen(), it doesn't read bytes. For example when in file were digits 1234 or letters. I had got the same as in file. <?php error_reporting(-1); class Archivator { public function readFile($file) { $stream = fopen($file, "rb"); while ($byteStr = fread($stream, 1)){...

Function to XOR two 128 bits. How do I generate 128 bit values?

c#,byte,bit,xor,bitarray
I'm trying to learn simple cryptology and as a starter I'm trying to achieve the following. A function, taking two 128 bit params (key and plaintext) as input and returning their XOR. I know XOR is not safe but I'm starting out with a simple example. This is what I...

Jump to Address after Branching in For Loop in MIPS

c,byte,branch,mips,bit
I am trying to code a program that checks if the 16 bits in an integer is a one or zero. I chose to implement this by shifting right one bit 15 times and checking if the first bit in each shift is a zero or non zero. Then, if...

High/low byte conversion for integer in ruby

ruby,integer,bit-manipulation,byte
We are having some small problems when converting data from hex to integer in ruby... We get a hardware signal, which is integer data -> converted to high and low byte, bitwise reversed -> string. Here is a example: Something between 0 and 75 => will be converted to "0x3938"......

C# to VB.net Byte Conversions

c#,.net,arrays,vb.net,byte
I'm trying to use some code from the Opus project in VB.net, it was originally written for C, but I am integrating it into another application... byte[] _notEncodedBuffer = new byte[0]; byte[] soundBuffer = new byte[e.BytesRecorded + _notEncodedBuffer.Length]; I'm not sure how these should be translated into VB.net, I have...

Reading files in c# with filestream and streamreader

c#,byte,filestream,streamreader,readline
I have a file, which contains data, I want to read it as byte[] and divide into 3 blocks. First line might be read as string, then 2nd block, might be 1-3 length of lines and all left bytes as block 3. I was wondering, how can I get that...

Java stream of byte. Read operation sometimes doesn't read what was written

java,stream,byte,inputstream,outputstream
I'm trying to implement a communication system with an automatic repeat request strategy. I use three classes: Transmitter, Channel, Receiver. I have a maximum number of byte for message (window). But when I receive the byte sent, sometimes I receive less bytes than window. Why? My code is this: Transmitter...

How to incrementally iterate through all possible values of a byte array of size n.

c#,loops,byte,bytearray
For my question n=16, but a generic answer would be appreciated too. So I have a byte array: byte[] key; My problem is that I want to iterate through all possible values of each element in this array, combined. I know this will take ages, and I'm not looking to...

Reading and writing bytes from/to a file

java,arrays,file,byte
I'm trying to write an array of bytes to a file and read them afterwards. It's important that the the array of bytes that I write is the same as the one that I read. I tried some methodes that were suggested here (File to byte[] in Java). However when...

Lua - Is it possible to check if 2 functions are equal?

function,lua,byte,equals
Is it either possible to get the size of a function in bytes to see if it matches another function similar to C++ sizeof operator, or evaluate two functions some other way to see if they are both equal without actually knowing what the function/s are? Example: local function equals(func1,...

Checking if the file is rar through its bytes

c#,security,byte
I am trying to verify that the file is a .rar file through its bytes for security purposes. Th following code is my code the only problem is that the sub-header is not matching with the one generated from the file. I noticed that is different for different file. Could...

Java, store in byte higher value than 127

java,casting,byte
For an assignment I get some bytes, make some calculations on their Binary values and have to return that calculated Stuff in a Byte Array. My Problem is now, that byte only stores up to 127, but my values can be up to 2^8-1 (11111111). I already tried to convert...

Swift Bit array to Bytes array (UInt8 array)

arrays,swift,type-conversion,byte,bit
I have array with bits: var bits: [Bit] and how could I convert it to bytes array: var bytes: [UInt8] For example I have 280 bits and I should have 35 UInt8 in bytes array. I can think of solution where I take 8bits and check if first is true,...

Store 4 different values in a byte

c,hex,byte
I have an assignment to do, but I have no clue where to start. I am not expecting and definitely do not want answers in code. I would like some guidance as in what to do because I feel a bit lost. Pack and unpack variables into a byte ....

How can I concatenate two bytes in java?

java,type-conversion,byte,bytearray,bucket
I have an integer called writeLocation that takes a value between [0,1023]. I need to store it in the last two bytes of a byte array called bucket. So, I figure I need to represent it as a concatenation of the array's last two bytes. How would I go about...

Remove '\x' from bytes

python,replace,binary,byte
I'm currently reading bytes from a file and I want to put two of these bytes into a list and convert them into an integer. Say the two bytes I want to read are \x02 and \x00 I want to join these bytes together before I convert them into an...

Why extended ASCII (special) characters take 2 bytes to get stored?

c++,c++11,byte,ascii,behavior
ASCII ranging from 32 to 126 are printable. 127 is DEL and thereafter are considered the extended characters. To check, how are they stored in the std::string, I wrote a test program: int main () { string s; // ASCII s += "!"; // 33 s += "A"; // 65...

Specified Cast Invalid Byte to int [duplicate]

c#,linq,casting,int,byte
This question already has an answer here: Puzzling Enumerable.Cast InvalidCastException 7 answers I'm trying to cast a list of byte to a list of ints. My List of bytes only contains one value 11. tmpMarketRights = AllMarketRights.Cast<int>().ToList(); 11 should be able to be casted to an INT does anyone...

How can I reverse order, byte wise, of a string in JavaScript?

javascript,string,byte
I have ded3e8c2e3460a97500c09d752a83c4eb44eda90998e33ce8d346a1174c0b97f and I want 7fb9c0.... I am using lodash and where's what I have so far mytxid = 'ded3e8c2e3460a97500c09d752a83c4eb44eda90998e33ce8d346a1174c0b97f' reverseTxid = _.chunk mytxid.split(''), 2 reverseTxid = reverseTxid.reverse() reverseTxid _.flattenDeep reverseTxid However, I get an error on the .reverse(): [TypeError: object is not a function] What am I doing...

BytesArray. ObjC to Swift

objective-c,arrays,swift,byte,nsdata
I am trying to write Swift implementation of the following ObjC(header file) code. #include <stddef.h> #ifndef VO_CERTIFICATE_TYPE #define VO_CERTIFICATE_TYPE typedef struct _voCertificate { const char* bytes; size_t length; } voCertificate; #endif static const char myCertificate_BYTES[] = { 103, 92, -99, 33, 72, 48, 119, -72, -77, 75, -88, 81, 113,...

Break bytes object into n equally sized blocks based on index

python,python-3.x,cryptography,byte,bytestring
I'm working on writing a script to break a repeating-key XOR (Vigenère) cipher. This involves determining some number (0 < n < maybe 50) then splitting up a bytes object into n smaller blocks, where the first block contains (from the original object) indexes n, 2n, 3n, next one contains...

open pdf from stream using pdfclown in c#

byte,filestream,pdfclown
I am really liking pdfclown in c# but I would like to open a pdf from a byte[] array or filestream. I have not found any examples of this for pdfclown. Could anyone help? An example would be something like: using (org.pdfclown.files.File file = new org.pdfclown.bytes.IInputStream(bytes)) { ... } Thanks...

Ror byte array with C#

c#,arrays,byte,byte-shifting
is there a way to Ror an entire byte[] by a specific amount? I've already done some research and found a solution to Rol a byte[] : public static byte[] ROL_ByteArray(byte[] arr, int nShift) { //Performs bitwise circular shift of 'arr' by 'nShift' bits to the left //RETURN: // =...

cannot convert from int to byte [duplicate]

java,casting,integer,byte
This question already has an answer here: Is addition of byte converts to int is because of java language rules or because of jvm? 4 answers I have a rather simple - but for me confusing - question. Assume the byte variabels a,b,c: byte a = 5; byte b...

Fast way to switch bits order? [closed]

java,c,go,byte,byte-order
I have a binary like this 10011011 My data store like this 10,01,10,11, but I want to reorder like this 11100110 The data look like 11,10,01,10.This operation same as ByteOrder convert but in bits level. Any fast bitop way to do this ? Currently, I have to decode this to...

Converting bytes to a long: Why do some implementations bitwise-AND each byte with 0xff?

java,type-conversion,bit-manipulation,byte,long-integer
I'm looking at the implementation of java.io's DataInputStream.readLong() in SE6: private byte readBuffer[] = new byte[8]; public final long readLong() throws IOException { readFully(readBuffer, 0, 8); return (((long)readBuffer[0] << 56) + ((long)(readBuffer[1] & 255) << 48) + ((long)(readBuffer[2] & 255) << 40) + ((long)(readBuffer[3] & 255) << 32) + ((long)(readBuffer[4]...

How to Calculate bfOffBits

c,bitmap,byte
I'm attempting to read and open a BMP file manually with C, and after reading the BMP specs and learning about how these files work, the header has definitions for the bytes that equal things like bfOffBits and biWidth. So for example the bfOffBits is equal to 4 bytes which...

golang: convert uint32 (or any built-in type) to []byte (to be written in a file)

arrays,go,byte,unsafe
I'm trying to convert an uint32 to a byte array (4 bytes) in Go using the unsafe library: h := (uint32)(((fh.year*100+fh.month)*100+fh.day)*100 + fh.h) a := make([]byte, unsafe.Sizeof(h)) copy(a, *(*[]byte)(unsafe.Pointer(&h))) The first two lines are correct, but then I get a runtime error ( unexpected fault address ) at the copy...

Converting a file in C# into byte array before parsing it into Java [duplicate]

java,c#,arrays,json,byte
This question already has an answer here: Java code - negative byte in byte array to C# 4 answers Forgive if this question is incredibly poorly phrased, but I'll do my best to explain what is (to me) a rather complex situation. I am fully aware that I am...

troubles with understanding how ASCII works

encoding,byte,ascii,bit
I have few questions about ASCII encoding: How come there is 127 characters definable in ASCII coding? It should be 7-bit, which means 2 to the power of 7 which equals 128. Where is the one character missing? When I save a textfile as a textfile.txt it should be saved...

How to convert from Int64 to hex and from hex to byte in c#

c#,hex,type-conversion,byte,int64
I am trying to send a byte array to micro controller over serial port. This is an example array which can successfully communicate with micro controller: byte[] getCommandArray = new byte[7] { 0x02, 0x0D, 0x01, 0x03, 0x30, 0x44, 0x03 }; What I need to do is read different values from...

Byte Array to Byte conversion error

c#,bit-manipulation,byte,bytearray,implicit-conversion
I am trying to flip the bits of an unsigned 32-bit integer and output the resultant integer. The following is my code. int numberOfTries = Convert.ToInt32(Console.ReadLine()); for (int i = 0; i < numberOfTries; i++) { uint input = Convert.ToUInt32(Console.ReadLine()); byte[] bInput = BitConverter.GetBytes(input); if (BitConverter.IsLittleEndian) Array.Reverse(bInput); byte[] result =...

how to take two words from a string and then add a - [closed]

c#,split,byte
Morning guys So I have this sanario a user enters text into a textbox the text is something in the following format 0123456789ABCDEF I want to be able to split the Text given by the user as 01-23-45-67-89-AB-CD-EF is this possible ? And then if possible how can I convert...

Cache size and set associative mapping

caching,byte,system,memory-address
Considering a machine with a byte-addressable main memory of 256 Kbytes and a block size of 8 bytes. With a set associative mapped cache consisting of 32 lines divided into 2-line sets. How many bytes will be stored in the cache? How many bits are there in the main memory...

blank space in strings from java/webservice(json) yields different byte arrays

java,json,string,byte
I am currently writing some acceptance tests to a jersey 2-0 webservice (json) before refactoring some methods in the project, and i have stumbled upon a problem with asserting blank-space strings from the webservice. I get the following output from my webservice: "Boxes": [ { "id": 1, "title": " ",...

byte array[] to byte is it possible in java?

java,byte,bytearray
I know in java we can't deal with bit directly, I want to know how can we convert an byte array[] to byte. Such that String bytestr="00000011"; byte[] noofbytes=bytestr.getBytes(); byte convbyte=(noofbytes[]) to byte Is it possible ? does any one have any idea ? Thanks....

Reading and writing image file as 'regular files'

python,image,byte
I am bound to using the Python standard library to read an image file, store its data in a variable, and then write a new image file containing the latter. I cannot simply copy nor move the image, but that does not matter. I also cannot use libraries such as...

Convert “FFFF” To byte [closed]

java,byte
I have a java String, and I have to convert it into byte, but the problem is byte doesn't allow this because of its range. What should I do. ? String num = "FFFF"; ...

Forcing Unicode in byte variable

java,string,unicode,byte,bytearray
I recently discovered that you convert a String to a byte array in the following manner: String S = "ab"; byte arr[] = S.getBytes(); Now, I tried with String "\u9999" and the answer was [63]. I thought it would be 9999 (mod 128) = 15 which is actually what we...

Transfer byte to char in Java - in CMD

java,cmd,char,byte
If I transfer byte to char in Java, I have following problem: In Netbeans is all O.K., but if I run program from Windows cmd I have a problem with charset. I don't know why. What to do? Code: char tmp = (byte) charFromByteInt; // it's byte in int variable...

Python3 How to make a bytes object from a list of integers

python,python-3.x,byte,bytearray
I have an array of integers (all less than 255) that correspond to byte values (i.e. [55, 33, 22]) how can I turn that into a bytes object that would look like b'\x55\x33\x22 etc. Thanks...

Read 16Bit Integer from 2 bytes big endian

java,integer,byte,big-endian
I'm trying to following up this tutorial about reading altitude from srtm-data. At the end I have to read 2 bytes from a file, which are big-endian and have to convert them to an integer in java. File file = new File(filename); InputStream inputStream = new FileInputStream(file); long length =...

File splitter method goes wrong when working with decimals

.net,vb.net,file,byte,filestream
I'm trying to develop a file-splitter method that splits a file into chunks of the desired size, it works perfect for files that has even filesize values (eg: if filesize is 2097152 bytes and I want to split it into two chunks, first chunk is 1048576 bytes and second chunk...

Get half bytes from a byte

java,byte,bytearray
I have a SHA-512 generated byte array from some bytes. 484c1514b468429967aa0c8e2ab6d99c14e7cd4a45605cb834ebfd3612a0cc9184510d8d0a9c92e636d82c065fa2db0e05ef5c2518153a6c4ca9eebbe8d7b475 When I iterate like below; for(byte x = 0; x < s512in.length; x++){ System.out.println(String.format("%02X ", s512in[x]) + " ); } I can get 48,4C,15.... but I want to get 4,8,4,C... from the byte array. How can I get that...

DES ciphertext length decreased during transmission and is not a multiple of 8 bytes [duplicate]

java,encryption,byte,des
This question already has an answer here: Why does my encrypted string looks like consisting of only question marks? 2 answers For a project a try to encrypt a pwd with DES algorithm. When I try this private static String key = "my8bcode"; /*Key 8 bytes or 56 bit...

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

java,byte,bytearray,thermal-printer,receipt
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...

difference of 2 byte arrays

java,arrays,byte,difference
I have a byte array which can have up to 4000 elements. These elementes can be byte/boolean(1 byte) int(2 byte) or long/float(4byte). They are not mixed, so one byte array only contains one data type If the array changes I want to get the position which is affected.. but if...

Python String to Bytes

python,byte,xbee
I have to pass in a string to xbee: xbee.tx(dest_addr='\x00\x01', data='hello world') I'd like just to input a string or integer like 01, but then I get the message: The data provided for 'dest_addr' was not 2 bytes long I'm using Python 2.7 How can this be resolved? Thanks....