Click here to Skip to main content
15,891,372 members
Home / Discussions / C#
   

C#

 
GeneralRe: encoding and decoding in BASE 10 Pin
stephen.darling14-Sep-10 12:50
stephen.darling14-Sep-10 12:50 
GeneralRe: encoding and decoding in BASE 10 [modified] Pin
Luc Pattyn14-Sep-10 13:27
sitebuilderLuc Pattyn14-Sep-10 13:27 
GeneralRe: encoding and decoding in BASE 10 Pin
stephen.darling14-Sep-10 13:36
stephen.darling14-Sep-10 13:36 
GeneralRe: encoding and decoding in BASE 10 Pin
Luc Pattyn14-Sep-10 13:43
sitebuilderLuc Pattyn14-Sep-10 13:43 
GeneralRe: encoding and decoding in BASE 10 Pin
stephen.darling14-Sep-10 14:05
stephen.darling14-Sep-10 14:05 
GeneralRe: encoding and decoding in BASE 10 Pin
AspDotNetDev14-Sep-10 14:34
protectorAspDotNetDev14-Sep-10 14:34 
GeneralRe: encoding and decoding in BASE 10 Pin
stephen.darling14-Sep-10 14:57
stephen.darling14-Sep-10 14:57 
GeneralRe: encoding and decoding in BASE 10 Pin
federico.strati15-Sep-10 3:11
federico.strati15-Sep-10 3:11 
Hi,

I don't know if I may help, but if I understand it well
your problem goes like this:

1. you have a fixed sequence of bytes, say you have
an array of 16 bytes. This may represents a number (more
precisily an unsigned or signed integer) in extended precision
in binary format (i.e. in base 2).

2. you want to handle this number and to convert it in
decimal base (base 10). Hence you get a nice base 10
representation outputted as a formatted string.

3. you want to be able to go back from the decimal
representation to the binary (base 2) one.

Trivial Example: do suppose your array is just 4 bytes long
(i.e. the standard size of an int)
namely you have in hex the value 0x0abc
stored as a four byte array in binary (base2) as:
(leading zeroes omitted) ...0000101010111100
you then want to convert it to the decimal representation
(base 10) with result: the string "2748".
and then be able to convert it back to its binary format
in base 2 in order to access it byte wise.

Well if this is right I think then you shall use
multiple precision arithmetique techniques: i.e.
you define a size (say 128 bytes) for your extended
precision integer and then you want a couple of functions
encodeBase10, decodeBase10 in order to be able to represent
such a number as a decimal string and convert back from it.

If such is your intention, you may take a look at the
GNU library "gmp", i.e. a multi precision library.

-----------

Instead of the solution above, you may want to do a translation byte
by byte, then the other method proposed in this thread
is just to output a converted value for each byte
in decimal taking care to pad with leading zeros where
needed, i.e. you transform from this:
(base 2) 00011010 00001111 00000111 10000011 - four bytes
to this
(base 10) 026 015 007 131 - string with 12 digits
and then convert back by grouping the string digits
3 by 3.

or if using ushort's instead of bytes,
you play with groups of 5 decimal digits
(always padding leading zeroes).

In this second case, for example, you have that a 25 long
string base10 digit represents 6 unsigned short numbers
and hence 12 bytes.

Hope this points you to the desired solution,
Cheers
GeneralRe: encoding and decoding in BASE 10 Pin
harold aptroot15-Sep-10 4:46
harold aptroot15-Sep-10 4:46 
GeneralRe: encoding and decoding in BASE 10 Pin
Luc Pattyn15-Sep-10 5:04
sitebuilderLuc Pattyn15-Sep-10 5:04 
Questiondynamic jpg photo Pin
benams14-Sep-10 9:45
benams14-Sep-10 9:45 
AnswerRe: dynamic jpg photo Pin
Pete O'Hanlon14-Sep-10 10:04
mvePete O'Hanlon14-Sep-10 10:04 
AnswerRe: dynamic jpg photo Pin
Luc Pattyn14-Sep-10 10:22
sitebuilderLuc Pattyn14-Sep-10 10:22 
AnswerRe: dynamic jpg photo Pin
T M Gray14-Sep-10 10:36
T M Gray14-Sep-10 10:36 
AnswerRe: dynamic jpg photo Pin
AspDotNetDev14-Sep-10 11:12
protectorAspDotNetDev14-Sep-10 11:12 
GeneralRe: dynamic jpg photo Pin
Luc Pattyn14-Sep-10 11:27
sitebuilderLuc Pattyn14-Sep-10 11:27 
QuestionPhones validator. Pin
Evgeni5714-Sep-10 9:37
Evgeni5714-Sep-10 9:37 
AnswerRe: Phones validator. Pin
T M Gray14-Sep-10 10:06
T M Gray14-Sep-10 10:06 
QuestionLINQ to SQL - Design Pattern Pin
brunoseixas14-Sep-10 8:09
brunoseixas14-Sep-10 8:09 
AnswerRe: LINQ to SQL - Design Pattern Pin
Ennis Ray Lynch, Jr.14-Sep-10 8:23
Ennis Ray Lynch, Jr.14-Sep-10 8:23 
GeneralRe: LINQ to SQL - Design Pattern Pin
OriginalGriff14-Sep-10 8:35
mveOriginalGriff14-Sep-10 8:35 
AnswerRe: LINQ to SQL - Design Pattern Pin
T M Gray14-Sep-10 8:43
T M Gray14-Sep-10 8:43 
AnswerRe: LINQ to SQL - Design Pattern Pin
PIEBALDconsult14-Sep-10 15:12
mvePIEBALDconsult14-Sep-10 15:12 
QuestionSimple Animation... Pin
stephen.darling14-Sep-10 7:01
stephen.darling14-Sep-10 7:01 
AnswerRe: Simple Animation... Pin
Ennis Ray Lynch, Jr.14-Sep-10 7:07
Ennis Ray Lynch, Jr.14-Sep-10 7:07 

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.