Re: converting numbers

1999-01-29 Thread Alexander N. Benner
hi

Ship's Log, Lt. David Stern, Stardate 280199.1148:

 OK, hex numbers are radix 16, octal radix 8, decimal radix 1.

As mentioned in an other mail, it's 10. There are no base 1 #s @all as 1^r for
all r is still 1 (besids you have always base# of digits starting with 0)

 Good.  Now I can convert between hex, octal and decimal.  

To extend yer knowledge ;-)
you can always do a # mod base ; # - # div base
Which will give you digit fer digit starting with the lowest one.

(Thell me if I abreviate 2 much :)

 I guess I'll have to determine when to use each based on context.

That is easy. Hex have capital letters, octals are 3 digits and start with a \
deciaml numbers are stored in i or o, binaries are just logical. Besids these
noone in there right mind uses any and whoever starts base 7 will be shot
anyway.

 Thanks!  Now, where is that coffee? :-)

Ah, can I have tea instead? A hot, black tea without any milk or sugar. :-)


Greetings
-- 
Alexander N. Benner; [EMAIL PROTECTED]; [EMAIL PROTECTED] (#Hosanna  #IXThYS) 
PROVERBS 30:4   
   Who hath ascended up into heaven, or descended?  
Who hath gathered the wind in His fists? Who hath bound the waters in a garment?
   Who hath established all the ends of the earth?  
 What is His name,   and what is His son's name,   if thou canst tell ? 


Re: converting numbers

1999-01-29 Thread Helge Hafting

 Where's the FM that tells how to convert numbers, like 0x11A to a 
 decimal?
You'll find it in any C manual, or try man strtol for the strtol() function.

If all you want is to convert to decimal, use this short C-program:
#include stdio.h

void main(int argc, char **argv)
{
while (*++argv) printf(%s == %i\n, *argv, strtol(*argv));
}

It simply prints all arguments as decimal numbers.  To use it, save it as
decimal.c  Then run gcc -O2 decimal.c and mv a.out decimal
Possibly also chmod oug+rx decimal

You can now use commands like ./decimal  25 0xFF 011 and get
25 == 25
0xFF == 255
011 == 9

The first one was an ordinary number, the other hexadecimal and the third one 
octal.

Helge Hafting


Re: converting numbers

1999-01-29 Thread M.C. Vernon

 If all you want is to convert to decimal, use this short C-program:
 #include stdio.h
 
 void main(int argc, char **argv)
  
This is undefined. main should return an int.

 {
 while (*++argv) printf(%s == %i\n, *argv, strtol(*argv));
exit(EXIT_SUCCESS);
 }

Matthew

-- 
Elen sila lumenn' omentielvo

[EMAIL PROTECTED],
Steward of the Cambridge Tolkien Society
Selwyn College Computer Support
http://www.cam.ac.uk/CambUniv/Societies/tolkien/
http://pick.sel.cam.ac.uk/


Re: converting numbers

1999-01-29 Thread Michael Laing
 Where's the FM that tells how to convert numbers, like 0x11A to a 
 decimal?

I use 'dc' for this sort of task, for example:

plum:~$ dc  Invoke the program
16  push 16 on the stack
i   pop 16 from the stack and set it as the input radix
11A push 0x11A on the stack
p   print the top number on the stack
282 by default, output radix is 10


One can go on and display the number in other radices (sp?):

8   push 8
o   set output radix
p   print
432 here it is in octal
2   push 2
o   set output radix
p   print
100011010   and now in binary
q   all done
plum:~$

'dc' has a good man page - and it's fun too!

Michael


Re: converting numbers

1999-01-29 Thread ivan
At 11:48 AM 1/28/99 -0800, David Stern wrote:
On Thu, 28 Jan 1999 12:17:34 CST, Andrew Ivanov wrote:
  Howdy,
  
  Where's the FM that tells how to convert numbers, like 0x11A to a 
  decimal?
 
 0x11A is in hex, and to convert it to dec is
 1*16^2 + 1*16^1 +10*16^0
 (A=10,B=11, C=12, D=13, E=14, F=15)

I should never have asked this question before having some coffee. :-)

 I may be wrong, but I think octal is in x0# format, so that 
 0x0300 would be an octal number.
 To convert that to dec is
 just 3*8^2+0*8^1+0*8^0, and ignore the leading 0 after x, which is used to
 idenbtify the radix.

OK, hex numbers are radix 16, octal radix 8, decimal radix 1.

So, a leading 0x indicates hex, and a leading 0 traditionally 
indicates octal, although the latter may require contextual information 
to distinguish between decimal, which should not be written with a 
leading zero, if I read Henning Makholm correctly (thanks Henning!), 
and I'll disregard the mention of binary.

Good.  Now I can convert between hex, octal and decimal.  

I guess I'll have to determine when to use each based on context.

Thanks!  Now, where is that coffee? :-)


http://amelia.experiment.db.erau.edu/ldp/HOWTO/mini/Coffee.html


-- 
David
[EMAIL PROTECTED]



-- 
Unsubscribe?  mail -s unsubscribe [EMAIL PROTECTED] 
/dev/null




converting numbers

1999-01-28 Thread David Stern
Howdy,

Where's the FM that tells how to convert numbers, like 0x11A to a 
decimal?

I think there are a few common formats of numbers and I'd like to be 
able to recognize them and transpose them, but I don't know where to 
look.

Thanks,
-- 
David

[EMAIL PROTECTED]



Re: converting numbers

1999-01-28 Thread Björn Elwhagen
On Thu, Jan 28, 1999 at 11:57:54AM -0600, David Stern wrote this:
 Where's the FM that tells how to convert numbers, like 0x11A to a 
 decimal?

0x0123 is if i don't reccall wrong the way to represent an octal number.
In that case you get it's decimal number this way.

123 base 8 is (3*8^0 + 2*8^1 + 1*8^2 = 3*1 + 2*8 + 1*64 = 83) base 10

Hope this helps you understand.

Regards

// Marwin

-- 
| Björn Elwhagen aka Marwin Finger [EMAIL PROTECTED] |  
| Student at Wexio University   for PGP public key.  |
| SwedenICQ: 356095  | 


Re: converting numbers

1999-01-28 Thread Andrew Ivanov
 Howdy,
 
 Where's the FM that tells how to convert numbers, like 0x11A to a 
 decimal?

0x11A is in hex, and to convert it to dec is
1*16^2 + 1*16^1 +10*16^0
(A=10,B=11, C=12, D=13, E=14, F=15)

I may be wrong, but I think octal is in x0# format, so that 
0x0300 would be an octal number.
To convert that to dec is
just 3*8^2+0*8^1+0*8^0, and ignore the leading 0 after x, which is used to
idenbtify the radix.

Binary...well, is binary.

HTH, 
 Andrew

Never include a comment that will help | Andrew Ivanov
someone else understand your code. | [EMAIL PROTECTED]
If they understand it, they don't  | ICQ: 12402354
need you.  |


Re: converting numbers

1999-01-28 Thread Henning Makholm
Björn Elwhagen [EMAIL PROTECTED] writes:

 0x0123 is if i don't reccall wrong the way to represent an octal
 number.

No. 0x always means that a hexadecimal number follows.

Ocal is traditionally indicated by having a leading zero but
no x. Outside contexts where one KNOWS that this convention is
or is not followed, it cannot be advised to write numbers with
leading zeroes.

-- 
Henning Makholm
http://www.diku.dk/students/makholm


Re: converting numbers

1999-01-28 Thread David Stern
On Thu, 28 Jan 1999 12:17:34 CST, Andrew Ivanov wrote:
  Howdy,
  
  Where's the FM that tells how to convert numbers, like 0x11A to a 
  decimal?
 
 0x11A is in hex, and to convert it to dec is
 1*16^2 + 1*16^1 +10*16^0
 (A=10,B=11, C=12, D=13, E=14, F=15)

I should never have asked this question before having some coffee. :-)

 I may be wrong, but I think octal is in x0# format, so that 
 0x0300 would be an octal number.
 To convert that to dec is
 just 3*8^2+0*8^1+0*8^0, and ignore the leading 0 after x, which is used to
 idenbtify the radix.

OK, hex numbers are radix 16, octal radix 8, decimal radix 1.

So, a leading 0x indicates hex, and a leading 0 traditionally 
indicates octal, although the latter may require contextual information 
to distinguish between decimal, which should not be written with a 
leading zero, if I read Henning Makholm correctly (thanks Henning!), 
and I'll disregard the mention of binary.

Good.  Now I can convert between hex, octal and decimal.  

I guess I'll have to determine when to use each based on context.

Thanks!  Now, where is that coffee? :-)
-- 
David
[EMAIL PROTECTED]



Re: converting numbers

1999-01-28 Thread Andrew Ivanov
Thanks for the correction:
 0x is hex, 0 is octal.
 
 OK, hex numbers are radix 16, octal radix 8, decimal radix 1.

No, decimal is radix 10 (base 10). Binary is base 2.

 I guess I'll have to determine when to use each based on context.

In written language the base is used as a subsript to the number, so that
you know what number system you work in.
 
 Thanks!  Now, where is that coffee? :-)

Mcoffee.


Never include a comment that will help | Andrew Ivanov
someone else understand your code. | [EMAIL PROTECTED]
If they understand it, they don't  | ICQ: 12402354
need you.  |


Re: converting numbers

1999-01-28 Thread Joey Hess
David Stern wrote:
 Where's the FM that tells how to convert numbers, like 0x11A to a 
 decimal?

This is in base 16, so:

[EMAIL PROTECTED]:~bc
...
ibase=16
11A
282-- result
quit

-- 
see shy jo


Re: converting numbers

1999-01-28 Thread Björn Elwhagen
On Thu, Jan 28, 1999 at 04:19:10PM -0600, Joey Hess wrote this:
 David Stern wrote:
  Where's the FM that tells how to convert numbers, like 0x11A to a 
  decimal?
 
 This is in base 16, so:
 

Hm...i obvilously didn't even look hard enough at the number given
since i didn't even notice the A...my fault...my tired eyes decieved
me... ;)

Regards

// Marwin

-- 
| Björn Elwhagen aka Marwin Finger [EMAIL PROTECTED] |  
| Student at Wexio University   for PGP public key.  |
| SwedenICQ: 356095  |