TIP: Click on subject to list as thread! ANSI
echo: c_plusplus
to: NEIL HELLER
from: WIM VELDHUIS
date: 1997-03-23 22:50:00
subject: BCD and `folding`

Neil Heller wrote in a message to All:
 NH> Given the following:
 NH> string foo = "12345678";
 NH> Is there a built-in or easily obtainable function for
 NH> converting foo to a "BCD type" (if there is such)?  Would
 NH> such a conversion automatically "fold" foo so that the
 NH> result would only require 4 bytes instead of the minimum
 NH> (9?) otherwise required?
I think the overhead involved in maintaining folded values does not outweight 
the troubles, especially when floating values are involved (like $15.6). In 
cases where a very large number of small values is used it might be 
worthwile, but I suppose you'd better use integers in that case as they will 
certainly be faster and smaller.
 NH> Just thinking about it some more, it seems that a BCD class
 NH> would be in order.  How could I go about investigating the
 NH> existance of same? 
AFAIK, A number of compilers have a BCD class (Borland, IBM). I'd start 
searching the internet for an implementation if I need one and my compiler 
hasn't one. The CUG (C Users Group) might be another source to check. Finally 
SNIPPETS might have an implementation.
 NH> Would anyone care to speculate on the comparitive
 NH> difficulties of doing this in C as opposed to C++?
In C you would need a different syntax to use the BCDs. In C++ you can make 
your class 'part of the language' by implementing the correct functions.
The actual algorithms however would be the same in both languages. You can 
build a C++ class from a C library implementing the necessary operations if 
you want (This makes it probably more maintainable if the code is used in C 
and in C++ projects, but it might introduce some overhead in the C++ 
sion).
mvg/wr
  
--- timEd/2 1.01.g3+
---------------
* Origin: LightHouse BBS ==> I am a H.U.G.O. Member ! (2:285/324.3)

SOURCE: echomail via exec-pc

Email questions or comments to sysop@ipingthereforeiam.com
All parts of this website painstakingly hand-crafted in the U.S.A.!
IPTIA BBS/MUD/Terminal/Game Server List, © 2025 IPTIA Consulting™.