Pregunta

I need to convert very large numbers from Base 256 (bytes) to Base 10 (decimal) in C# or Delphi. The actual goal is to represent contents of any given file as a very large decimal number and save it in a txt file, for example. We all know how to convert from one base to another, but the real challenge here is the size of the number. Any help would be appreciated.

¿Fue útil?

Solución

I strongly suspect that if you're using .NET 4 or higher, you'll be able to use the BigInteger(byte[]) constructor - and then convert the result to a decimal string if you want to (or just use it as a number). You may need to reverse the bytes in the input array depending on the endianness of your input.

Otros consejos

As of your update, this is pretty straightforward.

It sounds like you're trying to read the binary file in terms of chars, using some getc() function (the exact name escapes me). Every char is represented by one byte, hence 256 options. This gives chars a certain level of permeability with 8 bit ints. You should be able to read in a character and cast it to an integer, which will give you the decimal representation of the character's 8 bits.

Also chars aren't base 256, they're just 8 bit binary numbers.

Licenciado bajo: CC-BY-SA con atribución
No afiliado a StackOverflow
scroll top