Python Programming
 
Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
User Name:
Password:
Remember me

The Shed is going Social! Join us on FaceBook and Twitter and chime in on the conversation.

Go Back   Dev Shed ForumsProgramming LanguagesPython Programming

Reply
Add This Thread To:
  Del.icio.us   Digg   Google   Spurl   Blink   Furl   Simpy   Y! MyWeb 
Thread Tools Search this Thread Rate Thread Display Modes
 
Unread Dev Shed Forums Sponsor:
  #1  
Old September 14th, 2012, 04:12 AM
julianh julianh is offline
Registered User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Sep 2012
Posts: 5 julianh User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 53 m
Reputation Power: 0
Question Big Integers

IndentationError: unexpected indent
>>> for i in range(0,128):
... x = 1 << i
... print "%03d: 0x%X" % (i, x)

and eventually the last print show this ...

124: 0x10000000000000000000000000000000
125: 0x20000000000000000000000000000000
126: 0x40000000000000000000000000000000
127: 0x80000000000000000000000000000000

I am used to 32 and 64 bit integers, but here Python seems to be happily dealing with 128 bit integers. I was completely supprised that this works, it mus mean Python is storing values in some very wierd way. Can someone tell me whats going on here and how this works

Reply With Quote
  #2  
Old September 14th, 2012, 04:44 AM
Lux Perpetua Lux Perpetua is offline
Contributing User
Dev Shed Intermediate (1500 - 1999 posts)
 
Join Date: Feb 2004
Location: San Francisco Bay
Posts: 1,936 Lux Perpetua User rank is General 5th Grade (Above 100000 Reputation Level)Lux Perpetua User rank is General 5th Grade (Above 100000 Reputation Level)Lux Perpetua User rank is General 5th Grade (Above 100000 Reputation Level)Lux Perpetua User rank is General 5th Grade (Above 100000 Reputation Level)Lux Perpetua User rank is General 5th Grade (Above 100000 Reputation Level)Lux Perpetua User rank is General 5th Grade (Above 100000 Reputation Level)Lux Perpetua User rank is General 5th Grade (Above 100000 Reputation Level)Lux Perpetua User rank is General 5th Grade (Above 100000 Reputation Level)Lux Perpetua User rank is General 5th Grade (Above 100000 Reputation Level)Lux Perpetua User rank is General 5th Grade (Above 100000 Reputation Level)Lux Perpetua User rank is General 5th Grade (Above 100000 Reputation Level)Lux Perpetua User rank is General 5th Grade (Above 100000 Reputation Level)Lux Perpetua User rank is General 5th Grade (Above 100000 Reputation Level)Lux Perpetua User rank is General 5th Grade (Above 100000 Reputation Level)Lux Perpetua User rank is General 5th Grade (Above 100000 Reputation Level)Lux Perpetua User rank is General 5th Grade (Above 100000 Reputation Level) 
Time spent in forums: 1 Month 1 Week 2 h 12 m 42 sec
Reputation Power: 1312
Integers in Python are theoretically unbounded (though of course, they are actually bounded by the memory available on the machine). Technically, there are separate 'int' and 'long' types, but the distinction is essentially transparent, and you usually don't need to be aware of it.

Reply With Quote
  #3  
Old September 14th, 2012, 05:02 AM
julianh julianh is offline
Registered User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Sep 2012
Posts: 5 julianh User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 53 m
Reputation Power: 0
Big Integers

Thanks, yes I have a "C" mind set. I am writing code to test hardware that is 96 bits wide. Python is great being able to read 3 32 bit values and lets me do ...

bits = ((x<<64) | (y <<32) | z)

I was blown away when that worked. Great language

Reply With Quote
  #4  
Old September 15th, 2012, 01:10 AM
Lux Perpetua Lux Perpetua is offline
Contributing User
Dev Shed Intermediate (1500 - 1999 posts)
 
Join Date: Feb 2004
Location: San Francisco Bay
Posts: 1,936 Lux Perpetua User rank is General 5th Grade (Above 100000 Reputation Level)Lux Perpetua User rank is General 5th Grade (Above 100000 Reputation Level)Lux Perpetua User rank is General 5th Grade (Above 100000 Reputation Level)Lux Perpetua User rank is General 5th Grade (Above 100000 Reputation Level)Lux Perpetua User rank is General 5th Grade (Above 100000 Reputation Level)Lux Perpetua User rank is General 5th Grade (Above 100000 Reputation Level)Lux Perpetua User rank is General 5th Grade (Above 100000 Reputation Level)Lux Perpetua User rank is General 5th Grade (Above 100000 Reputation Level)Lux Perpetua User rank is General 5th Grade (Above 100000 Reputation Level)Lux Perpetua User rank is General 5th Grade (Above 100000 Reputation Level)Lux Perpetua User rank is General 5th Grade (Above 100000 Reputation Level)Lux Perpetua User rank is General 5th Grade (Above 100000 Reputation Level)Lux Perpetua User rank is General 5th Grade (Above 100000 Reputation Level)Lux Perpetua User rank is General 5th Grade (Above 100000 Reputation Level)Lux Perpetua User rank is General 5th Grade (Above 100000 Reputation Level)Lux Perpetua User rank is General 5th Grade (Above 100000 Reputation Level) 
Time spent in forums: 1 Month 1 Week 2 h 12 m 42 sec
Reputation Power: 1312
Quote:
Originally Posted by julianh
I was blown away when that worked. Great language
Python is famously one of the most programmer-friendly (and machine-unfriendly) programming languages out there. I see it in a way as a reaction to the crap that a lot of other languages make you put up with, though I don't know if that's any sort of official rationale. (I heard Guido van Rossum speak on Python a few years ago, and as I recall, he didn't spend time bashing other languages.)

Reply With Quote
  #5  
Old September 19th, 2012, 02:50 AM
julianh julianh is offline
Registered User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Sep 2012
Posts: 5 julianh User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 53 m
Reputation Power: 0
Post Big Integers

Interesting man/machine trade off you mention. Do all man friendly languages need to be difficult for a computer to execute ? On the one hand after many years of "C" programming my way of thinking has adapted and it still feels easier for me than Python which is unfamiliar. I am also reminded of the time I spent programming in Lisp on Symbolics hardware designed to execute it directly. Lisp is a pretty awsome language if you are into expert systems.

Reply With Quote
  #6  
Old September 19th, 2012, 04:12 AM
Scorpions4ever's Avatar
Scorpions4ever Scorpions4ever is offline
Banned ;)
Dev Shed God 9th Plane (9000 - 9499 posts)
 
Join Date: Nov 2001
Location: Woodland Hills, Los Angeles County, California, USA
Posts: 9,390 Scorpions4ever User rank is General 46th Grade (Above 100000 Reputation Level)Scorpions4ever User rank is General 46th Grade (Above 100000 Reputation Level)Scorpions4ever User rank is General 46th Grade (Above 100000 Reputation Level)Scorpions4ever User rank is General 46th Grade (Above 100000 Reputation Level)Scorpions4ever User rank is General 46th Grade (Above 100000 Reputation Level)Scorpions4ever User rank is General 46th Grade (Above 100000 Reputation Level)Scorpions4ever User rank is General 46th Grade (Above 100000 Reputation Level)Scorpions4ever User rank is General 46th Grade (Above 100000 Reputation Level)Scorpions4ever User rank is General 46th Grade (Above 100000 Reputation Level)Scorpions4ever User rank is General 46th Grade (Above 100000 Reputation Level)Scorpions4ever User rank is General 46th Grade (Above 100000 Reputation Level)Scorpions4ever User rank is General 46th Grade (Above 100000 Reputation Level)Scorpions4ever User rank is General 46th Grade (Above 100000 Reputation Level)Scorpions4ever User rank is General 46th Grade (Above 100000 Reputation Level)Scorpions4ever User rank is General 46th Grade (Above 100000 Reputation Level)Scorpions4ever User rank is General 46th Grade (Above 100000 Reputation Level) 
Time spent in forums: 1 Month 4 Weeks 1 Day 22 h 32 m 40 sec
Reputation Power: 4080
Until about version 2.2 or so, python used to distinguish between int and long (bignum) types:
Code:
x = 1
y = 1L

In older versions of python, it was possible to overflow x because it was an integer type and it would throw an OverflowError exception. y is a long/bignum variable and could be incremented as long as there's enough memory in the machine.

In newer versions of python (2.2 and above), the conversion happens automatically, so you can't overflow an int anymore. If the value can't be represented as an int, it will automatically promote it to a long type. So there's no need to add an 'L' at the end to initialize a variable as a long type any more.

The modification was discussed here:
http://www.python.org/dev/peps/pep-0237/
__________________
Up the Irons
What Would Jimi Do? Smash amps. Burn guitar. Take the groupies home.
"Death Before Dishonour, my Friends!!" - Bruce D ickinson, Iron Maiden Aug 20, 2005 @ OzzFest
Down with Sharon Osbourne

Last edited by Scorpions4ever : September 19th, 2012 at 04:21 AM.

Reply With Quote
Reply

Viewing: Dev Shed ForumsProgramming LanguagesPython Programming > Big Integers

Developer Shed Advertisers and Affiliates



Thread Tools  Search this Thread 
Search this Thread:

Advanced Search
Display Modes  Rate This Thread 
Rate This Thread:


Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
View Your Warnings | New Posts | Latest News | Latest Threads | Shoutbox
Forum Jump

Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
  
 


Powered by: vBulletin Version 3.0.5
Copyright ©2000 - 2013, Jelsoft Enterprises Ltd.

© 2003-2013 by Developer Shed. All rights reserved. DS Cluster - Follow our Sitemap