Re: [Tutor] Hex to Str - still an open issue

2005-02-10 Thread R. Alan Monroe
> I am not so clued up on the 'base 2' and 'base 8' stuff. > Care to explain that a little? Easy. Imagine the numerals 2,3,4,5,6,7,8,9 were never invented. You'd start counting at 0. Next would come 1. Now you've maxed out your first column so you have to carry to the next column, so next would c

Re: [Tutor] Hex to Str - still an open issue

2005-02-10 Thread Brian van den Broek
Johan Geldenhuys said unto the world upon 2005-02-10 00:43: I am not so clued up on the 'base 2' and 'base 8' stuff. Care to explain that a little? Johan On Tue, 2005-02-08 at 12:12, Pierre Barbier de Reuille wrote: Hi Johan, here's a go: We have 10 fingers. Not coincidentally, we have a base 10 n

Re: [Tutor] Hex to Str - still an open issue

2005-02-10 Thread Max Noel
On Feb 10, 2005, at 05:43, Johan Geldenhuys wrote: I am not so clued up on the 'base 2' and 'base 8' stuff. Care to explain that a little? Usually, we use base 10 numbers, that is, numbers that can be represented with 10 symbols (0, 1, 2, 3, 4, 5, 6, 7, 8, 9). Binary, or base 2, represents all

Re: [Tutor] Hex to Str - still an open issue

2005-02-10 Thread Alan Gauld
> I am not so clued up on the 'base 2' and 'base 8' stuff. > Care to explain that a little? base 2 is binary, base 8 is octal. We normally use base 10 decimal. The base refers to the biggest number that can be represented by a single digit. (Actually one less than the base because we start with

Re: [Tutor] Hex to Str - still an open issue

2005-02-09 Thread Johan Geldenhuys
I am not so clued up on the 'base 2' and 'base 8' stuff. Care to explain that a little? Johan On Tue, 2005-02-08 at 12:12, Pierre Barbier de Reuille wrote: MMmmhh ... no ! The number you wrote is equivalent to '010' and any number beginning by '0' and not followed by "x" will be considered

Re: [Tutor] Hex to Str - still an open issue

2005-02-08 Thread Pierre Barbier de Reuille
MMmmhh ... no ! The number you wrote is equivalent to '010' and any number beginning by '0' and not followed by "x" will be considered octal. So "10" in base 8 is ... 8 :) If you want to convert a number from base 2 to base 10 write : >>> int("10", 2) 2 Pierre Johan Geldenhuys a écrit :

Re: [Tutor] Hex to Str - still an open issue

2005-02-08 Thread Johan Geldenhuys
Hi everybody, I used binary.py and is a bit puzzled by the results I get when comparing the binary of decimal 2 and the value I get when I convert the binary to an int. >>> binary(2) '0010' >>> int(0010) 8 >>> Isn't the int value of this

Re: [Tutor] Hex to Str - still an open issue

2005-02-06 Thread Liam Clarke
Ah, thanks all. I wasn't thinking of base 2 numbers like base 10 - when you describe it like that, I get i. (100 = 10^2 + 0*10^1 + 0*10^0) I was thinking strictly in terms of a base 10 number described by flags for each power of 2, which (to me) would logically start from 2^0 and go right. And yea

Re: [Tutor] Hex to Str - still an open issue

2005-02-06 Thread Alan Gauld
> While I jest somewhat, that highlights a serious deficiency in my > education that becomes more and more apparent, which is in maths. Yes, its a sad fact. Good programming beyond basics does require a modicum of maths. You can learnn enough to do useful things without math, but there reaches a p

Re: [Tutor] Hex to Str - still an open issue

2005-02-06 Thread Karl Pflästerer
On 6 Feb 2005, [EMAIL PROTECTED] wrote: > Actually, generating the digits from the right complicates the algorithm quite > a bit. It's hidden in > the Python version, but s = str(i % 2) + s is a relatively expensive > operation here - it has to copy > all of s to make room for the new dig

Re: [Tutor] Hex to Str - still an open issue

2005-02-06 Thread Kent Johnson
Liam Clarke wrote: 4 is 001 (on a continuum of 2^0 to 2^n), but using the above approach we get 100. ?? 4 (decimal) is 100 (binary). Not because of how the conversion algorithm works, but because that is how we write numbers. The least-significant digit is always the rightmost digit. 001 is 1 in

Re: [Tutor] Hex to Str - still an open issue

2005-02-06 Thread Max Noel
On Feb 6, 2005, at 08:59, Liam Clarke wrote: Ah, yeah, gotta get me one of those textbooks. (Wait a minute, that would mean, my approach wasn't the textbook approach... /me salvages a little pride.) While I jest somewhat, that highlights a serious deficiency in my education that becomes more and mo

Re: [Tutor] Hex to Str - still an open issue

2005-02-06 Thread Liam Clarke
Ah, yeah, gotta get me one of those textbooks. (Wait a minute, that would mean, my approach wasn't the textbook approach... /me salvages a little pride.) While I jest somewhat, that highlights a serious deficiency in my education that becomes more and more apparent, which is in maths. Sheesh, if I

Re: [Tutor] Hex to Str - still an open issue

2005-02-06 Thread Alan Gauld
Liam, > Just looking at this - > i = 456 > s = '' > while i: > s = str(i % 2) + s > i/=2 > > This works, far simpler than mine, which is always infuriating, but my > question is, how exactly? This is the classic math treatment of how to calculate a binary number. Just keep dividing by two

Re: [Tutor] Hex to Str - still an open issue

2005-02-05 Thread Ismael Garrido
Liam Clarke wrote: Just looking at this - i = 456 s = '' while i: s = str(i % 2) + s i/=2 This works, far simpler than mine, which is always infuriating, but my question is, how exactly? if I have the number 15, when it divides by 2, it will become 7. Yet no error is introduced into the bin

Re: [Tutor] Hex to Str - still an open issue

2005-02-05 Thread Sandip Bhattacharya
Liam Clarke wrote: Sandip - Just looking at this - i = 456 s = '' while i: s = str(i % 2) + s i/=2 This works, far simpler than mine, which is always infuriating, but my question is, how exactly? if I have the number 15, when it divides by 2, it will become 7. Yet no error is introduced

Re: [Tutor] Hex to Str - still an open issue

2005-02-05 Thread Liam Clarke
Oh... and while I hate to use acronyms like this, I did indeed LOL. What happened was, I was feeding the strings I got out into the Windows calculator to check it was working. And they worked if they went backwards, and I was wondering why, and I vaguely recalled something I read in a Java book a

Re: [Tutor] Hex to Str - still an open issue

2005-02-05 Thread Sandip Bhattacharya
Tamm, Heiko wrote: Ok, thank you. Does anybody know how to convert a HEX into a BINARY? Just trying my hand out on python : To convert the value of i to binary: == i = 456 s = '' while i: s = str(i % 2) + s i/=2 print s = in case you have i in the form of

Re: [Tutor] Hex to Str - still an open issue

2005-02-05 Thread Kent Johnson
Liam, I think you misunderstand what endianness is. Big-endian and little-endian refer to the way a number is stored as bytes in the underlying memory of the computer. This is not something you generally need to worry about in a Python program. For example, consider the number 0x12345678. On most

Re: [Tutor] Hex to Str - still an open issue

2005-02-05 Thread Alan Gauld
> > unfortunately Python doesn't support binary in > > its string formatting(although it does in int()! > > Uh, question. Why not? It seems that all simple types should be included. I agree it has always seemed bizarre that inary is not included but octal is, IMHO binary is more useful as a repres

Re: [Tutor] Hex to Str - still an open issue

2005-02-05 Thread Liam Clarke
Jacob - just for you, begin your agitation for the next release please ;) binstring.py, as attached. (also pasted up - http://www.rafb.net/paste/results/5feItM57.html) Creating this, was just a brain teaser, but I was thinking 'what if I wanted to make this for the standard library.' And so you

Re: [Tutor] Hex to Str - still an open issue

2005-02-04 Thread Jacob S.
The binary value is the same as the hex value. The binary representation is 00010100, but unfortunately Python doesn't support binary in its string formatting(although it does in int()! Uh, question. Why not? It seems that all simple types should be included. Since the computer stores it as bin

Re: [Tutor] Hex to Str - still an open issue

2005-02-04 Thread Alan Gauld
> Does anybody know how to convert a HEX into a BINARY? The easiest way I know is to use a lookup table on the octal representation. def bin(n): bins = ['000','001','010,'011','111'] result = '' for c in oct(n): result += bins[int(c,8)] return result HTH, Alan G Author

Re: [Tutor] Hex to Str - still an open issue

2005-02-04 Thread Alan Gauld
> But I'm looking for a solution to convert a Hex number > into binary, decimal, interger numbers. WE need to be very specific about our terminology here. All numbers in the computer are stored in binary. Only the string representation on the screen is in decimal, octal, hex etc. > What is the

Re: [Tutor] Hex to Str - still an open issue

2005-02-04 Thread Bill Mill
t; Heiko > > -Original Message- > From: Pierre Barbier de Reuille [mailto:[EMAIL PROTECTED] > Sent: Friday, February 04, 2005 2:55 PM > To: Tamm, Heiko > Subject: Re: [Tutor] Hex to Str - still an open issue > > Oh ! You meant the other way around ? > > If

Re: [Tutor] Hex to Str - still an open issue

2005-02-04 Thread Kent Johnson
more guesses. Kent Tamm, Heiko wrote: Ok, thank you. Does anybody know how to convert a HEX into a BINARY? Best regards Heiko -Original Message- From: Pierre Barbier de Reuille [mailto:[EMAIL PROTECTED] Sent: Friday, February 04, 2005 2:55 PM To: Tamm, Heiko Subject: Re: [Tutor] Hex t

RE: [Tutor] Hex to Str - still an open issue

2005-02-04 Thread Tamm, Heiko
Ok, thank you. Does anybody know how to convert a HEX into a BINARY? Best regards Heiko -Original Message- From: Pierre Barbier de Reuille [mailto:[EMAIL PROTECTED] Sent: Friday, February 04, 2005 2:55 PM To: Tamm, Heiko Subject: Re: [Tutor] Hex to Str - still an open issue

Re: [Tutor] Hex to Str - still an open issue

2005-02-04 Thread Kent Johnson
You might be interested in these: http://groups-beta.google.com/group/comp.lang.python/msg/c2cb941ea70dcdad http://aspn.activestate.com/ASPN/Cookbook/Python/Recipe/111286 Kent Tamm, Heiko wrote: Thank you, Pierre, But I'm looking for a solution to convert a Hex number into binary, decimal, interge

RE: [Tutor] Hex to Str - still an open issue

2005-02-04 Thread Tamm, Heiko
Thank you, Pierre, But I'm looking for a solution to convert a Hex number into binary, decimal, interger numbers. E.g.: What is the the binary value of the hex number 1F4. Is there a function available, or how can it be done? Kind regards and a nice weekend Heiko -Original Messa