PDA

View Full Version : The program cannot work correctly for more than "FFFFF"



Ryan111
3rd April 2015, 11:06
Hi everybody
Today I was seeing and working around this project:

www.youtube.com/watch?v=HMxVDuk1gLo

There are two links in this youtube page to download the source code and executable program. you can download them.
after downlaoding it, I found out that it cannot work for more than "FFFFF". why?
I changed all of the numeric variables to quint64 to see if it would work for 64bit but still it doesn't work. I attached the changed source code. in your opinion what's wrong with this program?

Lesiok
3rd April 2015, 11:22
What it means cannot work for more than "FFFFF" ?

Ryan111
3rd April 2015, 12:01
This program is Decimal, Binary and Hexadecimal Converter. it can convert any Hex value less than "FFFFF" to Dec or Bin but for more than this value, you can just see somethings like this:

http://upload.tehran98.com/upme/uploads/b899ea3bb9e167572.png

while for less than "FFFFF" everythings is ok. look:

http://upload.tehran98.com/upme/uploads/b89933e4502068951.png

Added after 24 minutes:

And also for "FFFFFFFFFFFFFFFF":

http://upload.tehran98.com/upme/uploads/bd4b079f26aa7f9e1.png

Looks like the calculator of windows has the same problem(wink). look:

http://upload.tehran98.com/upme/uploads/148baefbe13fef271.png


LoL!:D

maybe I have to use an array to figure out this problem.:p

stampede
3rd April 2015, 12:01
Clearly it is broken. Is it your program ? What do you want us to do about this bug ?
Btw. if you just want to convert between different representations you can use built-in "calc" app on windows.

Ryan111
3rd April 2015, 12:10
Is it your program ?
Actually no.

What do you want us to do about this bug?
Any simple idea to solve it? any seggestion and recommends?

Btw. if you just want to convert between different representations you can use built-in "calc" app on windows.
Yes but it has some bugs or problems. then it make me to write a good converter for myself.

wysota
3rd April 2015, 12:25
The programs probably work on some integral types therefore they won't be able to convert numbers which don't fit into those types. 0xFFFF FFFF FFFF FFFF is a 128 bit number therefore you need a datatype that can hold 128 bit unsigned numbers (e.g. uint_128_t if supported by your compiler). Other than that you can split a text string into smaller ones, perform a conversion of each of those chunks and assemble the result into textual representations again.

ChrisW67
3rd April 2015, 21:01
A 64-bit signed integer with all its bits set to 1 does indeed represent -1 decimal in two's complement representation. Windows calculator has that right.