|
When you set the value, you use an @ before the string. This tells C# to treat backslashes as backslashes rather than escape characters, so you are writing four characters to the registry, not two as you intended.
What is this talk of release? I do not release software. My software escapes leaving a bloody trail of designers and quality assurance people in its wake.
|
|
|
|
|
You have already used the double backslash and the @ prefix in two of your strings, so you should be able to see what is wrong with the first one.
|
|
|
|
|
Have a read of this
String Literals C#[^]
Every day, thousands of innocent plants are killed by vegetarians.
Help end the violence EAT BACON
|
|
|
|
|
To add to what the others said, don't use the registry unless you absolutely have to: access is restricted in "modern" OS's and likely to become more so, not less.
Unless there is a very, very good reason, you are much better off using application config files, or storing information in the folders intended for that. This might help: Where should I store my data?[^]
Those who fail to learn history are doomed to repeat it. --- George Santayana (December 16, 1863 – September 26, 1952)
Those who fail to clear history are doomed to explain it. --- OriginalGriff (February 24, 1959 – ∞)
|
|
|
|
|
<pre>using System;
using System.IO;
using System.Collections.Generic;
using System.Linq;
using System.Text;
namespace Applica
{
class Program
{
static void Main(string[] args)
{
DirectoryInfo da = new DirectoryInfo("C:\\Folder");
FileInfo[] Arr = da.GetFiles();
if (Arr.Length == 0)
{
throw new InvalidOperationException("No files found.");
}
FileInfo ap = Arr[Arr.Length - 1];
long Totbyte = ap.Length;
string filePath = ap.FullName;
Console.WriteLine("Total Bytes = {0} bytes", Totbyte);
string temPath = Path.GetTempFileName();
byte[] data = File.ReadAllBytes(filePath);
File.WriteAllBytes(temPath, data);
decimal[] arry = new decimal[Totbyte];
for (int count = 0; count < data.Length; count++)
{
arry[count] = data[count];
}
byte[] data2 = new byte[Totbyte];
for (int count = 0; count < arry.Length; count++)
{
data2[count] = (byte)arry[count];
}
if (data2.Length != data.Length)
{
throw new InvalidOperationException("Wrong length!");
}
for (int index = 0; index < data.Length; index++)
{
if (data[index] != data2[index])
{
throw new InvalidOperationException("Data has changed at index " + index);
}
}
string filePath2 = Path.Combine("C:\\check", Path.GetFileName(filePath));
File.WriteAllBytes(filePath2, data2);
data = File.ReadAllBytes(temPath);
data2 = File.ReadAllBytes(filePath);
if (data2.Length != data.Length)
{
throw new InvalidOperationException("Wrong length!");
}
for (int index = 0; index < data.Length; index++)
{
if (data[index] != data2[index])
{
throw new InvalidOperationException("Data has changed at index " + index);
}
}
}
}
}
|
|
|
|
|
The decimal type[^] is 128 bits, or 16 bytes long. So 821903722 * 16, will take up 13,150,459,552 bytes, which is rather more memory than you have available. You could simplify this by reading your file in blocks and converting a block at a time. But, a more important issue is what are you actually trying to achieve, since all your program is doing, when it works, is to create a copy of the file? The conversion to decimals is totally redundant.
|
|
|
|
|
See the BinaryReader[^] and BinaryWriter[^] classes.
They can read/write files in chuncks.
If your file is a text file, see the StreamReader and StreamWriter classes instead.
.Net is limited to 2Gb for an object if I'm not mistaken. That might be the reason. ReadAllBytes does what it says: It reads ALL the bytes, so for large files, this could be an issue.
Hope this helps.
|
|
|
|
|
It is not redundant if you want to see a file in a way that looks simple. Decimal is very simple. It is kindergarten simple, which is my level in programming currently. I want to treat all files like binary. I don't want to specify type such as text. The streamwriter class is reading line by line, but that is not what I want. Is there anyway to do with binary chunks for one file?
|
|
|
|
|
1. I'm not saying anything about redundancy, perhaps you meant to reply to the other member?
2. I'm not saying you should StreamReader or StreamWriter, I was merely giving an alternative for the BINARY Reader/Writer classes in case it was an option.
3. If you would open the links the members indicate several methods for reading (and writing) chunks of data.
|
|
|
|
|
Yes, I was commenting what another member wrote about "redundant." I did look up the streamwriter and saw that it would not work for me. Thank you.
|
|
|
|
|
StreamWriter is for text. BinaryWriter is for binary files or did you make a typ-o?
|
|
|
|
|
computerpublic wrote: It is not redundant if you want to see a file in a way that looks simple. It still is redundant.
computerpublic wrote: Decimal is very simple. A byte is a small integer number, without any decimals. What good does it do to convert it to a decimal? How does it make things simpeler?
Bastard Programmer from Hell
If you can't read my code, try converting it here[^]
|
|
|
|
|
computerpublic wrote: It is not redundant if you want to see a file in a way that looks simple. Decimal is very simple.
Just a guess, but are you trying to view the bytes as decimal (base-10) numbers? You don't need to convert to the decimal type for that.
"These people looked deep within my soul and assigned me a number based on the order in which I joined."
- Homer
|
|
|
|
|
computerpublic wrote: t is not redundant Of course it is, you convert bytes to decimal and then immediately convert them back to bytes, so it serves no purpose.
computerpublic wrote: Is there anyway to do with binary chunks for one file? Yes, use the Read method[^] of the BinaryReader class[^], and read in blocks as I suggested previously.
More importantly, you still have not explained why you want to convert these bytes to decimal in the first place. Perhaps if you did, we would be able to make some more useful suggestions.
|
|
|
|
|
Honestly, how are decimals easier to understand?
Note, a byte is a value from 0 to 255. You convert it to decimal and it is a value from 0 to 255.
Maybe you are getting confused by the term "binary".
Binary means 2 things:
A value that can be only 0 or 1. So, instead of seeing 255 you see 11111111.
A representation of data that's not text-only.
So, a byte is usually used to read binary data. This doesn't mean it only reads 0 or 1. It can still be seen as 0, 1, 2, 3, 100 etc... limited to 255. It is actually not limited to visible characters (so, it is not text).
Your conversion from byte to decimal is only converting 8 bit values to 128 bit values that contain the same important data (a value from 0 to 255)... and then you are converting it back.
So, it is not redundant. It is completely useless.
Redundant is for those cases that it actually generates a result that could be easily obtained. In this case you are doing completely useless work.
If what you want is to read a file that has lines like this:
01010101
11111111
00010001
And you want to understand those values, you need to:
Read each line as string.
Convert each string to a byte.
Then, you convert the numeric value back to a string.
So, 11111111 (binary) will become 255 (decimal). This is a decimal representation, not the decimal type.
|
|
|
|
|
Hi,
Im looking for a simple way to convert byte array 32bits to byte array 16bits... I already asked in stackoverflow but the response was bad.
byte [] data = Convert.FromBase64String("-- my string encoded")
var skipBytes = 0;
byte[] data16bit;
int samples ;
skipBytes = 0;
samples = data.Length / 4;
data16bit = new byte[samples * 2];
int writeIndex = 0;
int readIndex = 0;
for(var i = 0; i < samples; ++i)
{
readIndex += skipBytes;
data16bit[writeIndex++] = data[readIndex++];
data16bit[writeIndex++] = data[readIndex++];
}
Please help or enlighten me 
|
|
|
|
|
Member 10607992 wrote: I already asked in stackoverflow but the response was bad.
That's probably because your question isn't clear. A byte is always 8 bits; there are no 16-bit or 32-bit byte arrays.
From your title, I'd guess you're trying to resample an audio file? If that's the case, you can either P/Invoke the Audio Compression Manager[^], or use a third-party library like NAudio[^].
"These people looked deep within my soul and assigned me a number based on the order in which I joined."
- Homer
|
|
|
|
|
Mmm you are right, It's my wave file encoded in 32 bits... but not the byte arrays.
Im working on Wave header with MemorySream . If it doesn't work i 'll check Audio Compression ManagerM . Anyway when i get trough this, i will reply the answear. All example with resample are kinda easy but Im beginng with byte array and i need to change Wave Header for my new byte array, Im not working with Files like all Naudio example. Thanks
|
|
|
|
|
|
Wave format does not know about "byte arrays". The format is specified by samples per second (in your case: 11025 vs. 8000), bits per sample (32 vs. 16), sample type (floating point vs. whole number - 32 bit is typically float while 16bit is typically an Int16), and channels (you did not provide any information about that - mono, stereo, something else?).
Look at the source code of NAudio, though they start with files, they soon continue with streams.
|
|
|
|
|
hi guys,
I used memery stream to resample with Naudio.
I write all wave header but i have a problem, my Subchunk2ID (offset 36 ) is too big.
My length wave file is about 20 Hours but when Im playing it's the good lenght (4/3 second).
i checked and its when i write "Data"... what am I missing
bwl.Write(new char[4] { 'R', 'I', 'F', 'F' });
bwl.Write(length);
bwl.Write(new char[8] { 'W', 'A', 'V', 'E', 'f', 'm', 't', ' ' });
bwl.Write((int)16);
bwl.Write((short)1);
bwl.Write(program.channels);
bwl.Write(program.samplerate);
bwl.Write((int)(program.samplerate * ((program.BitsPerSample * program.channels) / 8)));
bwl.Write((short)((program.BitsPerSample * program.channels) / 8));
bwl.Write(program.BitsPerSample);
bwl.Write(new char[4] { 'd', 'a', 't', 'a' });
bwl.Write(buffer);
This line
bwl.Write(new char[4] { 'd', 'a', 't', 'a' });
is 10 times bigger than the initial file !!!!
|
|
|
|
|
How to get the dns suffix name I need to add this suffix to hostname. 
|
|
|
|
|
Which DNS suffix? Please give proper details of what you are trying to do, and what part of your code is not working.
|
|
|
|
|
my current machine dns suffixname.I would like to connect to remote host through tcp protocol socket.
|
|
|
|
|
Your DNS suffix is not going to help you to connect to a remote host; you need to know the name or IP address of the remote system itself.
|
|
|
|