difference b/t signed & unsigned decimal integer?

Put your programming skills to the test in these challenges.

difference b/t signed & unsigned decimal integer?

Post by ghostheadx2 on Wed Apr 15, 2015 2:59 pm
([msg=87709]see difference b/t signed & unsigned decimal integer?[/msg])

So looking at this page:

http://www.tutorialspoint.com/python/python_strings.htm

I'd like to know what the difference between a signed decimal integer i.e. %d %i etc. and %u

I'd like the difference simplified. Thanks. :)

Best,

ghostheadx2
ghostheadx2
Contributor
Contributor
 
Posts: 728
Joined: Wed Nov 19, 2014 1:19 am
Blog: View Blog (0)


Re: difference b/t signed & unsigned decimal integer?

Post by ghost107 on Wed Apr 15, 2015 6:15 pm
([msg=87710]see Re: difference b/t signed & unsigned decimal integer?[/msg])

unsigned is part of N(natural number), it means positive numbers(0, 1, 2, 3, ...)
signed is part of Z(integer), means positive and negative numbers (...-2, -1, 0, 1, 2...)

- %d and %i are the same and will print the numbers as integers
- %u does not work, only prints the value as signed integer(if you print %u with a negative value it will print the negative value, for example -1 will print -1 instead of the integer max value)
- %o prints the number in Octal base( if decimal is base 10, uses numbers from 0-9, the octal is base 8 uses numbers 0-7, so decimal value 8 in octal will have value of 10 )
- %x print in Hexadecimal number base 16 ( uses numbers from 0-9 and A-F, A = 10, B = 11, C = 12, D = 13, E= 14, F = 15, so total value is 0-15)
- %f prints floating points(if you print 1.25 with %f will print 1.25)
Last edited by ghost107 on Wed Apr 15, 2015 6:42 pm, edited 4 times in total.
User avatar
ghost107
Poster
Poster
 
Posts: 321
Joined: Wed Jul 02, 2008 7:57 am
Blog: View Blog (0)


Re: difference b/t signed & unsigned decimal integer?

Post by cyberdrain on Wed Apr 15, 2015 6:22 pm
([msg=87712]see Re: difference b/t signed & unsigned decimal integer?[/msg])

To add to that, because of space constraints in registers/CPUs/memory, unsigned integers can be larger than signed integers.
Free your mind / Think clearly
User avatar
cyberdrain
Expert
Expert
 
Posts: 2160
Joined: Sun Nov 27, 2011 1:58 pm
Blog: View Blog (0)



Return to Programming

Who is online

Users browsing this forum: No registered users and 0 guests