> < ^ From:

^ Subject:

------------- Dear GAP Forum,

Enis Karaaslan raised the question of reading numbers in hexadecimal format.

It is easy to write a GAP function to convert a string containing a

hexadecimal representation of an integer into the corresponding integer. Here

is a simple version:

hexdigits := "0123456789abcdefABCDEF"; hexvals := [0,1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,10,11,12,13,14,15]; hextoint := function(s) local c,n; n :=0; for c in s do n := 16*n + hexvals[Position(hexdigits,c)]; od; return n; end;

This is neither very efficient, since each digit is searched for linearly, nor

very robust, since it completely fails to handle non-digits, but it gives an

idea.

The Operation ReadLine can then be used to extract lines from the file as

strings and they can be (stripped of spaces and newlines and) passed to this

function.

The suggestion of allowing GAP to read hexadecimal numbers in its normal input

stream, perhaps denoted by 0x as C does, has been made, and seems a reasonable

one. It remains "on the list" to be implemented when time permits.

Steve

Miles-Receive-Header: reply

> < [top]