Text representation of a number... 
Author Message
 Text representation of a number...

Greetings.
I'm in need of an algorithm to take an eight-byte integer (not supported
as a native type in Windows 3.1), and print its ASCII representation
to a file.  This number comes from a server that stores the number in
big-endian format, but I could switch it if necessary.  If anyone
knows such an algorithm, or has a pointer to one, it'd be much
appreciated.
                            TIA
                                Joel
-----------------------------------------------------------

Life is an illusion - so enjoy it while it lasts.



Wed, 29 Jul 1998 03:00:00 GMT  
 Text representation of a number...

: Greetings.
: I'm in need of an algorithm to take an eight-byte integer (not supported
: as a native type in Windows 3.1), and print its ASCII representation
: to a file.  This number comes from a server that stores the number in
: big-endian format, but I could switch it if necessary.  If anyone
: knows such an algorithm, or has a pointer to one, it'd be much
: appreciated.

Well, gcc sources are bound to have one of both available.  Okay, maybe not
the printout part, but at least the whole arithmetic library needed to
implement one.  GNU and 4.4BSD libc sources have %q support in their
respective *printf functions.

/Alby



Fri, 31 Jul 1998 03:00:00 GMT  
 Text representation of a number...

Quote:

>Greetings.
>I'm in need of an algorithm to take an eight-byte integer (not supported
>as a native type in Windows 3.1), and print its ASCII representation
>to a file.  This number comes from a server that stores the number in
>big-endian format, but I could switch it if necessary.  If anyone

read the number into an array of 8 chars
using binary shifts, re-create the number into an unsigned long int
fprintf to file using %lu
(output may be padded by specifying width or 0width to pad with '0'


Sun, 02 Aug 1998 03:00:00 GMT  
 Text representation of a number...

Quote:


>>I'm in need of an algorithm to take an eight-byte integer (not supported
>>as a native type in Windows 3.1), and print its ASCII representation
>>to a file.  This number comes from a server that stores the number in
>>big-endian format, but I could switch it if necessary.  If anyone

>read the number into an array of 8 chars
>using binary shifts, re-create the number into an unsigned long int
>fprintf to file using %lu

Do people actually _think_ before posting "solutions"?

How the hell can you fit a 64-bit integer into a 32-bit unsigned long,
using binary shifts?  People working in the data compression field would
_love_ to find the answer :-)

[1.  Remove all zeroes.  They don't carry any voltage anyway.  2.  Count the
 ones.  You have no more than 64.  Any number < 64 can be easily fit in
 an unsigned long.  Sheesh, doesn't anyone *think* anymore? -mod]

[I leave uncompression as an exercise for God. -mod]

Dan
--
Dan Pop
CERN, CN Division

Mail:  CERN - PPE, Bat. 31 R-004, CH-1211 Geneve 23, Switzerland



Sun, 02 Aug 1998 03:00:00 GMT  
 Text representation of a number...

: Greetings.
: I'm in need of an algorithm to take an eight-byte integer (not supported
: as a native type in Windows 3.1), and print its ASCII representation
: to a file.  This number comes from a server that stores the number in
: big-endian format, but I could switch it if necessary.  If anyone
: knows such an algorithm, or has a pointer to one, it'd be much
: appreciated.
:                             TIA
:                                 Joel
I hope this helps.  I'm unsure of how you are holding the eight-byte
integer inside of the program.  I would imagine you are using something
along the lines of an unsigned long for the lower bits and a signed long
for the higher bits.  As for an ASCII representation of this number, I
would suggest using some bit shifting to accomplish this.  (This
conversion might be easier if done in hex rather than decimal.)  You
would have to consecutively mask off the last four bits, convert this to
its hex equivalent, and then shift off these four bits and repeat.

        Kevin



Sun, 02 Aug 1998 03:00:00 GMT  
 Text representation of a number...

: : Greetings.
: : I'm in need of an algorithm to take an eight-byte integer (not supported
: : as a native type in Windows 3.1), and print its ASCII representation
: : to a file.  This number comes from a server that stores the number in
: : big-endian format, but I could switch it if necessary.  If anyone
: : knows such an algorithm, or has a pointer to one, it'd be much
: : appreciated.
i fear  you wont get around defining the operation "div 10"
and "mod 10" on your longish integer type.  Once you have that,
you can repeatedly  use  x mod 10 as the next decimal digit  and then
replace x by (x div 10) until x is zero.
  this will yield the decimal representation in reverse order (least
significant digit first), but stringreversal shouldn't be a problem.

remains the problem of div'ing(mod'ing) your number-representation.
you'll have to build it using the / and %  of smaller integertypes. (not
really easy, but it's possible)  
  have a look on how you divide big numbers by hand (on paper), and then
try to re-implement that algorithm.
--

/* Hereby i grant you my non-exclusive permission to share my opinions */



Sun, 09 Aug 1998 03:00:00 GMT  
 
 [ 6 post ] 

 Relevant Pages 

1. Text representation of a number...

2. function: representation of a number in any number system

3. Converting string representation of hexadecimal number to an integer

4. large hex number representation

5. Converting number to its verbal representation

6. Borlandc debuger number representation

7. Getting and using numbers in a text file

8. Getting and using numbers in a text file

9. Getting and using numbers in a text file

10. Getting and using numbers in a text file

11. determining the number of lines in a text file

12. Determining line number in a text file

 

 
Powered by phpBB® Forum Software