Click here to Skip to main content
15,504,703 members
Home / Discussions / C#
   

C#

 
GeneralRe: Converting Byte to Decimal Pin
harold aptroot11-Feb-14 9:56
harold aptroot11-Feb-14 9:56 
GeneralRe: Converting Byte to Decimal Pin
computerpublic11-Feb-14 10:07
computerpublic11-Feb-14 10:07 
GeneralRe: Converting Byte to Decimal Pin
harold aptroot11-Feb-14 10:15
harold aptroot11-Feb-14 10:15 
GeneralRe: Converting Byte to Decimal Pin
computerpublic11-Feb-14 10:29
computerpublic11-Feb-14 10:29 
GeneralRe: Converting Byte to Decimal Pin
computerpublic11-Feb-14 11:09
computerpublic11-Feb-14 11:09 
GeneralRe: Converting Byte to Decimal Pin
harold aptroot11-Feb-14 23:03
harold aptroot11-Feb-14 23:03 
GeneralRe: Converting Byte to Decimal Pin
computerpublic12-Feb-14 8:31
computerpublic12-Feb-14 8:31 
GeneralRe: Converting Byte to Decimal Pin
harold aptroot12-Feb-14 9:55
harold aptroot12-Feb-14 9:55 
Follow the error message. It tells you what to do. But I'm a nice guy (well, sometimes), so here you go:
C#
using System;
using System.IO;
using System.Collections.Generic;
using System.Linq;
using System.Text;
 
namespace Applica
{
    class Program
    {
        static void Main(string[] args)
        {
            long Totbyte = 0;
            string filePath = null;
            DirectoryInfo da = new DirectoryInfo("C:\\Folder");
            FileInfo[] Arr = da.GetFiles();
 
            foreach (FileInfo ap in Arr)
            {
                Totbyte = ap.Length;
                filePath = ap.FullName;
            }
            Console.WriteLine("Total Bytes = {0} bytes", Totbyte);
            string temPath = Path.GetTempFileName();
            byte[] data = new byte[Totbyte];
 
            if (File.Exists(temPath))
            {
                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];
             //   Console.WriteLine("Byte to Decimal = {0},,,,,, count = {1}", arry[count], count);
            }
            ///////////ABOVE: READ IN FILE AND CHANGE EACH BYTE TO DECIMAL
            ///////////BELOW: TRYING TO REVERSE THE ABOVE PROCESS
            byte[] data2 = new byte[Totbyte];
            for (int count = 0; count < arry.Length; count++)
            {
                data2[count] = (byte)arry[count];
            }
            FileStream file = new FileStream(filePath, FileMode.Create);
            BinaryWriter binarystream = new BinaryWriter(file);
            binarystream.Write(data2);
            binarystream.Close();
        }
    }
}

By the way, may I ask what this is for? Converting all the bytes of a file to decimals is a pretty weird thing to do. I have a gut feeling there might be a nicer solution.
GeneralRe: Converting Byte to Decimal Pin
computerpublic12-Feb-14 10:08
computerpublic12-Feb-14 10:08 
GeneralRe: Converting Byte to Decimal Pin
harold aptroot12-Feb-14 10:16
harold aptroot12-Feb-14 10:16 
GeneralRe: Converting Byte to Decimal Pin
computerpublic12-Feb-14 10:24
computerpublic12-Feb-14 10:24 
GeneralRe: Converting Byte to Decimal Pin
harold aptroot12-Feb-14 10:49
harold aptroot12-Feb-14 10:49 
SuggestionRe: Converting Byte to Decimal Pin
Richard Deeming11-Feb-14 10:34
mveRichard Deeming11-Feb-14 10:34 
QuestionConverting Byte Array to Integer Array Pin
computerpublic11-Feb-14 5:10
computerpublic11-Feb-14 5:10 
AnswerRe: Converting Byte Array to Integer Array Pin
Pete O'Hanlon11-Feb-14 5:15
mvaPete O'Hanlon11-Feb-14 5:15 
GeneralRe: Converting Byte Array to Integer Array Pin
computerpublic11-Feb-14 5:31
computerpublic11-Feb-14 5:31 
GeneralRe: Converting Byte Array to Integer Array PinPopular
Pete O'Hanlon11-Feb-14 5:42
mvaPete O'Hanlon11-Feb-14 5:42 
QuestionPayment Using Visa Cards Pin
Zeyad Jalil11-Feb-14 2:58
professionalZeyad Jalil11-Feb-14 2:58 
AnswerRe: Payment Using Visa Cards Pin
V.11-Feb-14 3:18
professionalV.11-Feb-14 3:18 
AnswerRe: Payment Using Visa Cards Pin
OriginalGriff11-Feb-14 4:03
mveOriginalGriff11-Feb-14 4:03 
GeneralRe: Payment Using Visa Cards Pin
Dave Kreskowiak11-Feb-14 8:27
mveDave Kreskowiak11-Feb-14 8:27 
JokeRe: Payment Using Visa Cards Pin
AmitGajjar11-Feb-14 21:00
professionalAmitGajjar11-Feb-14 21:00 
GeneralRe: Payment Using Visa Cards Pin
Dave Kreskowiak12-Feb-14 5:22
mveDave Kreskowiak12-Feb-14 5:22 
GeneralRe: Payment Using Visa Cards Pin
V.11-Feb-14 21:28
professionalV.11-Feb-14 21:28 
AnswerRe: Payment Using Visa Cards Pin
GuyThiebaut11-Feb-14 10:54
professionalGuyThiebaut11-Feb-14 10:54 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.