473,396 Members | 1,891 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,396 software developers and data experts.

To reperent a number into minimum number of digits

151 100+
Hi,
How a number can be represented into minimum number of digits?
5678432145151257 should be represented into 2 digit number. Like
LOC890808 should also be represented into 2 digit number. Is there any algorithm exist like that ......


Thanks in advace.
Aug 12 '09 #1
8 4089
donbock
2,426 Expert 2GB
I'm sorry, I don't understand your question.

What do the letters "LOC" at the start of your second example mean?

In the first example (5678432145151257), it seems self-evident that 16 decimal digits are needed to represent this number -- but you suggest it can be accomplished in two digits. We must have different definitions in mind for the word digit.
Aug 12 '09 #2
Man4ish
151 100+
I am planning to compress the number of digits/char. so if it is 16 digit number, it should be represented by 2 or 3 numbers only. is it possible?

@donbock
Aug 12 '09 #3
Hi ,
Please explain with real time Example
Aug 12 '09 #4
Man4ish
151 100+
I am planning to compress the data so in my mind technique is like kepping the digits
2345665 into digit number say 26 (which has come after some manipulation, addition subtraction etc). Is there any algo for that?
@sridhard2406
Aug 12 '09 #5
JosAH
11,448 Expert 8TB
Every integral number X can be represented with one digit in radix X+1: it'll be the last digit in that radix representation; the problem is then that you have to store that radix X+1 somewhere.

kind regards,

Jos
Aug 12 '09 #6
Man4ish
151 100+
Please explain with example.

@JosAH
Aug 12 '09 #7
Banfa
9,065 Expert Mod 8TB
Jos is talking about changing bases however it is not a solution to your problem because as Jos points out even if you change the base to conver the number ro a 1 digit number then you still have to store the base that you converted it the number to otherwise the data is meaningless.

As an example suppose the X = 15 in Jos example, I can convert to base 15+1 = 16 (hexadecimal). I can now store the number in 1 digit as F but for F to be meaningful I have to remember that the base is 16 so I need to store F and 16 which is more data.

The basic answer to your question is that it is not possible consider any decimal number with it's binary representation, for example

1234 10011010010

To remove even a single binary digit you would need to find one that has no meaning, however every single bit has a meaning in this number.

Instead then let us consider hexadecimal and find an algorithm that will compress any 4 digit hexadecimal number and lets not be ambitious lets find an algorithm that compress every number by 1 bit.

So we are going to compress every hexadecimal number

HHHH in binary BBBB BBBB BBBB BBBB

to a binary number with one less digit

CCC CCCC CCCC CCCC

Or that is we will compress any 16 digit binary number to a 15 digit binary number. And this is the crux of the problem because a 16 digit binary number has 65536 possible values but a 15 digit binary number has only 32768 possible values so regardless of the algorithm used if it existed then some of the input values would compress to the same output values and you would not be able to decompress them without additional information.

It is not possible to find an algorithm that provide lossless compression of any digit sequence by any amount let alone to specifically 2 digits.

All lossless compression algorithms rely on identifying and removing redundant data in one manner or another. If you can not identify any redundant data in the data you wish to compress then it is not compress-able.

A number sequence from 0 - N where every value has meaning by definition has no redundant values.
Aug 12 '09 #8
donbock
2,426 Expert 2GB
A lookup table can be used to compress a sparse distribution of large numbers. For example, if you only have to deal with 256 different 16-digit numbers then you write those values into a table and represent the values with the 1-byte index into the table. For a small sequence of large numbers the overhead of the table swamps the benefits of the compression. You can readily compute how many large numbers need to be compressed before you start to see benefits.

The lookup table approach can still be used even when there are more large numbers than slots in the table (see Hash function).

Other compression techniques share that limitation: there are conditions where the compression technique actually increases the size of the message. Google is your friend: Data compression.

@Banfa
For example, you may have heard that it is customary to add a CRC value to a data message to insure its integrity. The CRC value is much shorter than the message ... is this an example of the compression you seek? Consider a 1 KB message. That's 1024 8-bit bytes, or 8192 bits; therefore there are 2^8192 different messages that could be sent. A 16-bit CRC has 2^16 different values. This means that on average there are 2^8176 different messages that all share the same CRC value.
Aug 12 '09 #9

Sign in to post your reply or Sign up for a free account.

Similar topics

6
by: simina | last post by:
Hi... I have a form with 4 number fields: phone area, phone number, cell area, cell number. I did a function that checks the "number" issue for all 4 fields in the same time (because the code is...
6
by: Jovo Mirkovic | last post by:
Hi, I have to make a program which will generate 100,000 different ID numbers (for example 2345-9341-0903-3432-3432 ...) It must be really different, I meen it can not be a similar (like...
27
by: Luke Wu | last post by:
Is there a C function that returns the number of digits in an input int/long? example: numdigits(123) returns 3 numdigits(1232132) returns 7
7
by: ffrugone | last post by:
I need to create a method for a web page I'm building that encrypts a number from 1 to 1000 into a 4 digit hex code. I know nothing about cryptography. Can anyone steer me in the right direction?
109
by: jmcgill | last post by:
Hello. Is there a method for computing the number of digits, in a given numeric base, of N factorial, without actually computing the factorial? For example, 8! has 5 digits in base 10; 10! has...
23
by: neha_chhatre | last post by:
which is the best format specifier(data type) if i have to work with decimal number. also please tell me the syntax for truncating a decimal number please reply as soon as possible
20
by: jacob navia | last post by:
Hi "How can I round a number to x decimal places" ? This question keeps appearing. I would propose the following solution #include <float.h> #include <math.h>
1
by: jlt206 | last post by:
This code <?php include("counter.php")?> on the webpage produces the count number. (function code below) I want to place the current number into a variable $MemberNo or into a FormField to be sent...
10
by: Matthias | last post by:
Dear newsgroup. I want to write a template function which accepts either integer or floating point numbers. If a certain result is not a whole number and if the template parameter is an...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.