Solved

unique 48 bits number to unique 32 bits number

Posted on 2006-07-20
8
192 Views
Last Modified: 2010-04-01
Hi,
as stated in the header, does anyone know an algorithm or something like that which enables me to use a 48 bit unique number and store it as a unique 32 bit number??
Regards
0
Comment
Question by:TError104
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
8 Comments
 
LVL 45

Accepted Solution

by:
sunnycoder earned 20 total points
ID: 17145091
Hi TError104,

It is not possible to store 2^48 unique numbers are 2^32 unique numbers ... there are bound to be collisions and there will be several 48 bit numbers which will map to common 32 bit numbers .... this is unavoidable ....

Cheers!
sunnycoder
0
 
LVL 12

Assisted Solution

by:rajeev_devin
rajeev_devin earned 20 total points
ID: 17145127
If you want to store a 48 bit number then use two data members instead

32 bit integer
16 bit short integer

which is 48 bit in size.
0
 
LVL 7

Assisted Solution

by:nafis_devlpr
nafis_devlpr earned 20 total points
ID: 17145213
you can use the segment:offset method, like save the first 16bit in a 16bit short int as the segment and the next 32bit in a 32bit int as the offset, by this i mean the bit mask of the 48bit in a 16+32 bit split

you can try union

union INT
      {
            unsigned short int first16;
            unsigned int next32;
      };
or a struct or union of 6 char data

union INT
      {
            unsigned char s[6];
      };

Nafis
0
Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
LVL 30

Assisted Solution

by:Axter
Axter earned 20 total points
ID: 17145532
Why not use a 64 bit integer to store the 48bit number?

__int64 My48_bitNum;
0
 
LVL 39

Expert Comment

by:itsmeandnobodyelse
ID: 17145538
Do you know the whole set of 48-bit numbers where the uniqueness needs to keep guaranteed ? If yes, you might take the index of each number as a unique 32 bit equivalence (I assume the size of the set is less than 4 billions).

If no, you could simply count the 4bit numbers you have to convert and and return the count value as a unique id:

typedef unsigned short UI48[3];

unsigned int I48ToI32(UI48 ui48)
{
     static unsigned int count = 0;
     return ++count;
}

In case you could get the same input twice  you would need to store all numbers converted to a dictionary and check for existence before incrementing count.

struct UI48
{
    unsigned short us3[3];
    bool operator<(const UI48& u) const { return us3[0] < u.us3[0] ||
                                                ( us3[0] == u.us3[0] && us3[1] < u.us3[1]) ||
                                                ( us3[0] == u.us3[0] && us3[1] == u.us3[1]  && us3[2] < u.us3[2]);
                                                         }
    bool operator==(const UI48& u) const { return ( us3[0] == u.us3[0] && us3[1] == u.us3[1] && us3[2] == u.us3[2]); }
};

unsigned int I48ToI32(UI48 ui48)
{
     static unsigned int count = 0;
     static std::map<UI48, unsigned int> uimap;
     if (uimap.find(ui48) == uimap.end())
           uimap[ui48] = ++count;
     return  uimap[ui48];
}

Regards, Alex
0
 
LVL 53

Expert Comment

by:Infinity08
ID: 17145566
First of all : what do you want to achieve ?

1) lossless compression : impossible as stated by sunnycoder (unless there are max. 2^32 valid values possible for the 48bit integer)

2) conversion of a 48bit value to a 32bit value : only possible if the maximum value of the 48bit integer is 2^32-1

3) something else : please specify
0

Featured Post

Enroll in May's Course of the Month

May’s Course of the Month is now available! Experts Exchange’s Premium Members and Team Accounts have access to a complimentary course each month as part of their membership—an extra way to increase training and boost professional development.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Title # Comments Views Activity
Quicksort a dynamic deque 33 84
PDF library for Delphi 2 149
How do I save this device context as a .bmp or a picture of some kind? 2 79
Gaming Software 1 39
Article by: SunnyDark
This article's goal is to present you with an easy to use XML wrapper for C++ and also present some interesting techniques that you might use with MS C++. The reason I built this class is to ease the pain of using XML files with C++, since there is…
This article shows you how to optimize memory allocations in C++ using placement new. Applicable especially to usecases dealing with creation of large number of objects. A brief on problem: Lets take example problem for simplicity: - I have a G…
The goal of the video will be to teach the user the concept of local variables and scope. An example of a locally defined variable will be given as well as an explanation of what scope is in C++. The local variable and concept of scope will be relat…
The viewer will learn how to pass data into a function in C++. This is one step further in using functions. Instead of only printing text onto the console, the function will be able to perform calculations with argumentents given by the user.

752 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question