How to read a dword from a binary file with java?
Tag : java , By : user143729
Date : March 29 2020, 07:55 AM
I hope this helps you . DataInputStream.readFully() and .readInt(). You may have to do something about the (unspecified) byte order though. If that's an issue, ByteBuffer.getInt(), after setting the appropriate byte order.
|
FStream reading a binary file written with Delphi's binary writer
Tag : cpp , By : billputer
Date : March 29 2020, 07:55 AM
will be helpful for those in need It seems pretty clear that somewhere along the way the data is being mangled between an 8 bit text encoding and a 16 bit encoding. The spurious first character is almost certainly the UTF-16 BOM. One possible explanation is that the Delphi developer is writing UTF-16 encoding text to the file. And presumably you are expecting an 8 bit encoding.
|
Reading a binary file and using new line as a delimiter to create binary chunks
Tag : chash , By : Liviu Aileni
Date : March 29 2020, 07:55 AM
hop of those help? I am totally out of my element when it comes to binary files. I need to read a binary file and break it into chunks using new line as the delimiter. I have tried googling this but its come up empty. Any help on this would be appreciated. It Has to be opened as binary file. , Helper Method class MyEnumerableExtensions
{
//For a source containing N delimiters, returns exactly N+1 lists
public static IEnumerable<List<T>> SplitOn(
this IEnumerable<T> source,
T delimiter)
{
var list = new List<T>();
foreach (var item in source)
{
if (delimiter.Equals(item))
{
yield return list;
list = new List<T>();
}
else
{
list.Add(item);
}
}
yield return list;
}
}
var path = "binary-file.bin";
var delimiter = (byte)'\n';
var chunks = File.ReadAllBytes(path)
.SplitOn(delimiter)
.ToList();
|
Converting from hex to binary and binary to hex, without using conversion, reading txt file to find errors in RAM
Date : March 29 2020, 07:55 AM
it should still fix some issue OK, your question was unclear to me. The reason that you get only one number is that you call from main to hexToBinary, loop thru the entire file with this method, and then return to main. After that, you call to binaryToDecimal which prints out the value of result, which is the last value it got from hexToBinary. What you need to do is to read a value from the file, convert it to binary and then to decimal and proceed to the next value. One way of doing it is this: public static String hexToBinary(String hex) throws IOException {
String result = "";
String binVal; // the binary value of the Hex
for (int i = 0; i < hex.length(); i++) {
char hexChar = hex.charAt(i);
switch (hexChar) {
case ('0'):
binVal = "0000";
break;
case ('1'):
binVal = "0001";
break;
case ('2'):
binVal = "0010";
break;
case ('3'):
binVal = "0011";
break;
case ('4'):
binVal = "0100";
break;
case ('5'):
binVal = "0101";
break;
case ('6'):
binVal = "0110";
break;
case ('7'):
binVal = "0111";
break;
case ('8'):
binVal = "1000";
break;
case ('9'):
binVal = "1001";
break;
case ('A'):
binVal = "1010";
break;
case ('B'):
binVal = "1011";
break;
case ('C'):
binVal = "1100";
break;
case ('D'):
binVal = "1101";
break;
case ('E'):
binVal = "1110";
break;
case ('F'):
binVal = "1111";
break;
default:
binVal = "invalid input";
break;
}
result += binVal;
}
return result;
}
public static Double binaryToDecimal(String result) {
double j=0;
for(int i=0;i<result.length();i++)
{
if(result.charAt(i)== '1')
{
j= j + Math.pow(2, result.length()-1-i);
}
}
return j;
}
public static void main(String args[]) throws IOException {
Scanner infile = new Scanner(new File("RAMerrors.txt"));
String result;
Double decimal;
while (infile.hasNextLine()) {
String line = infile.nextLine();
Scanner input = new Scanner(line);
String hex = input.next();
result = hexToBinary(hex);
System.out.println("Binary of " + hex + ":" + result);
decimal = binaryToDecimal(result);
System.out.println("Decimal value: " + decimal);
}
|
Error C2664 'BOOL CryptBinaryToStringW(const BYTE *,DWORD,DWORD,LPWSTR,DWORD *)': cannot convert argument 4 from 'std::u
Date : March 29 2020, 07:55 AM
Hope this helps You're assigning a std::unique_ptr object to a variable of type wstring that is not allowed. If you want to assign the value of pwszBuffer to a variable of type wstring, you should get the unique_ptr's value and then assign it to the variable. You can get the value of std::unique_ptr by calling its * operator:void func(std::unique_ptr<std::wstring>& input_ptr) {
// Do something...
}
std::unique_ptr<std::wstring> function_input;
func(function_input);
void func(std::unique_ptr<std::wstring>&
input_ptr) {
// Do something...
}
std::unique_ptr<std::wstring> function_input;
func(std::move(function_input));
|