![]() |
|
#1
|
|||
|
|||
C code, matching binary pairs of numbersHi!
I'm having a little trouble with a problem I hope someone can please help with! I'm looking at binary numbers that only differ by one particular pair of elements... (it has to be exactly one, they can't be the same or differ by two etc)... So a and b in this example: a = [21] - [01(01)01] b = [25] - [01(10)01] differ only by their middle pair... and so because it's only a difference of 1 pair, the value here would be 0.5... Whereas a and b in this example: a = [37] - (10)(01)01 b = [25] - (01)(10)01 differ by 2 pairs, so the value here would be 0... Only numbers that have a single pair difference are given the value 0.5... Given 2 decimal numbers I'd like to be to pass them to a function which will convert them to binary numbers of length N (variable dependent on array size), and check for the pair situation described above and then return the appropriate value... This is what I have so far: CPP / C++ / C Code:
|
|
#2
|
|||
|
|||
Re: C code, matching binary pairs of numbersQuote:
Huh??? What does this mean? How are you representing the numbers? What does "array size" have to do with anything? If the values of the variables are represented internally as 32-bit binary numbers, then you could do something like the following: Code:
If this doesn't satisfy your requirements, then maybe you could give us a better statement of the problem. Regards, Dave Last edited by davekw7x : 10-Nov-2007 at 09:06.
|
|
#3
|
|||
|
|||
Re: C code, matching binary pairs of numbersto convert from decimal to binary is easy.
you just have a loop that says the following.. CPP / C++ / C Code:
other and group every other two. this code is also assuming you only have 8-bit binary numbers at the most (255 being the highest decimal value you can use). MonkO |
|
#4
|
|||
|
|||
Re: C code, matching binary pairs of numbersAnother way would be to use a union with bit allocations.
CPP / C++ / C Code:
|
|
#5
|
|||
|
|||
Re: C code, matching binary pairs of numbersThanks very much for all the help... I finally figured it out:
CPP / C++ / C Code:
|
Recent GIDBlog
Toyota - 2008 September Promotion by Nihal
| Thread Tools | Search this Thread |
| Rate This Thread | |
|
|
Similar Threads
|
||||
| Thread | Thread Starter | Forum | Replies | Last Post |
| New to programming (Homework Help) | fishguts | Miscellaneous Programming Forum | 1 | 12-Sep-2007 10:50 |
| How to sort random access file? | wmmccoy0910 | C Programming Language | 12 | 04-Sep-2006 03:40 |
| how to make a 'INTEGER to BINARY' code? | justaHSstudent | C++ Forum | 1 | 02-Oct-2005 14:22 |
| Linear Search | eccoflame | C Programming Language | 3 | 19-Apr-2005 08:36 |
| Problem with int mixed with char,... | leitz | C++ Forum | 17 | 07-Dec-2004 20:56 |
Network Sites: GIDNetwork · GIDWebHosts · GIDSearch · Learning Journal by J de Silva, The