473,385 Members | 1,958 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,385 software developers and data experts.

Hash Function

5
hi,im doing my assignment,,but sadly i dnt knw how to do...help me please b4 19april2010
Code a hash function, which computes the index number based on the MMU ID, which is
a 10-digit key. The hashing algorithm used to compute the hash index is given as follows:
• Partition the 10-digit key (yyyyyzzzzz) into two 5-digit numbers: yyyyy and
zzzzz.
• Add the two partitioned numbers, yyyyy and zzzzz.
• Truncate the addition result, and keep only the last three digits.
Use the function header given below. The function will accept an unsigned integer, ID
which stores the MMU ID, compute accordingly and return the computed hash index.
int hashfunc(unsigned int ID);
What is your MMU ID? ______________________
What is the hash index based on your MMU ID? ______________________
Apr 16 '10 #1
10 1920
newb16
687 512MB
What does that 'b4' thingie mean? Then, how are you going to jam 10-digit number ( e.g. 9 bil. ) into unsigned int ( that is, I assume, 32-bit on most platforms)? To extract higher part, you can use modulo(%) operator.
Apr 16 '10 #2
boolat
5
well,i have to submit by this monday..and im totally desprate..
the 10 digit mean,if the id number entered is 1231112020.
then divided into two parts of yyyyy and xxxxx.
help me please..im bad in programming =((
Apr 16 '10 #3
newb16
687 512MB
I am somewhat aware what 10-digit number is. My question was about the choice of -- "int hashfunc(unsigned int ID);" <- this prototype for the function - what if number entered it e.g. nine billion, that has 10 digits, but doesn't fit into unsigned int?
>help me please..im bad in programming =((

Try, for a beginning, to write the part of dividing them into two parts in a some math notation, without programming.
Apr 16 '10 #4
boolat
5
well i got the hint to do formula part..
here is my formula..but i dont knw if its correct or not..

int hashfunc(unsigned int ID){
int a,b,c;
float j,k;
int e=0;
j=ID/1000.0;
a=j,".";
b=j,"\n";
c=a+b;
k=c/1000.0;
e=k,"\n";
return e;

for the maths part its like add yyyyy+zzzzz
then truncate??i dont knw how..then keep the last digit..
Apr 16 '10 #5
jkmyoung
2,057 Expert 2GB
?? what?
Examples. if you have ID = aaaaaaaaab, and you want to get the value of b, we go:
b = ID % 10;

ID = aaaaaaaacc
cc = ID % 100;

ID = aaaaaaddee
ee = ID % 100;
dd = (ID % 10000) / 100 OR
dd = (ID / 100) %100

Hope this helps.
Apr 16 '10 #6
newb16
687 512MB
This doesn't do what it is supposed to do.
a=j,".";
It assigns j to a, then calculates value of pointer to "." string and discards it. It looks like that you once saw a printf() called and try to reproduce it.

Then, there is no need to use floating point here, and divisor for the higher half should be 100000, not 1000.
Apr 16 '10 #7
boolat
5
i dont knw how to partition the 10 digits of int 5 and 5..
meaning for example if my id is 1234567890
then i need to divide to (12345)yyyyy+ 67890 (zzzzz) while after that i have to add them up...
Apr 16 '10 #8
newb16
687 512MB
It's result of dividing by 100000 and remainder of dividing by 100000. Then add them and apply modulo operator to get last 3 digits.
Apr 16 '10 #9
boolat
5
yes.i know.but still it did divide into two partition right??
correct me if im wrong
Apr 16 '10 #10
newb16
687 512MB
No, the last code snippet you posted did not do it right.
Apr 16 '10 #11

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

Similar topics

3
by: Markus Dehmann | last post by:
I have a class "Data" and I store Data pointers in an STL set. But I have millions of inserts and many more lookups, and my profiler found that they cost a lot of runtime. Therefore, I want to...
2
by: Bryan Olson | last post by:
The current Python standard library provides two cryptographic hash functions: MD5 and SHA-1 . The authors of MD5 originally stated: It is conjectured that it is computationally infeasible to...
4
by: flipdog | last post by:
Hello all, I didn't know there is a thread on hash function started in this newsgroup so reposted my posting from another group. Hope I can have some feedbacks. I am new to hash table. I came...
6
by: barcaroller | last post by:
I'm looking for a hash function (in C) that will convert a string of arbitrary length (but less than 1024 chars) to a reasonably-unique 16-bit short integer. Can anyone point me to such a hash...
6
by: thecodemachine | last post by:
Hi, I'm looking for a fast and simple one to one hash function, suitable for longer strings (up to 2048 in length). I'd like keys to be relatively short, I doubt I'd be creating more than 256...
12
by: Arash Partow | last post by:
Hi all, I've ported various hash functions to python if anyone is interested: def RSHash(key): a = 378551 b = 63689 hash = 0
21
by: Johan Tibell | last post by:
I would be grateful if someone had a minute or two to review my hash table implementation. It's not yet commented but hopefully it's short and idiomatic enough to be readable. Some of the code...
21
by: Hallvard B Furuseth | last post by:
Is the code below valid? Generally a value must be accessed through the same type it was stored as, but there is an exception for data stored through a character type. I'm not sure if that...
11
by: Douglas Dude | last post by:
how much time does it take to lok for a value - key in a hash_map ? Thanks
139
by: ravi | last post by:
Hi can anybody tell me that which ds will be best suited to implement a hash table in C/C++ thanx. in advanced
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: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
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
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
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
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
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
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...

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.