|
List Info
Thread: "ocaml_beginners"::[] how to obtain an unsigned int32?
|
|
| "ocaml_beginners"::[] how to
obtain an unsigned int32? |

|
2006-06-22 09:50:06 |
Hi all,
I currently work on an embedded system which has native 32
bits integers. I have
some trouble with int in caml because their signed ones.
I would like to know if there is an easy way to get an
Unsigned int of 32 bits
format with Caml ?
Is it correct to add 2^31 to the signed int32 in the case it
is negative (31th
bit set to 1) and get the result with an int64 ?
Thanks a lot
------------------------ Yahoo! Groups Sponsor
--------------------~-->
Yahoo! Groups gets a make over. See the new email design.
http://us.click.yahoo.com/XISQkA/lOaOAA/yQLSAA/saFolB/TM
------------------------------------------------------------
--------~->
Archives up to August 22, 2005 are also downloadable at http://www.connettivo.net/cntprojects/ocaml_beginners/
The archives of the very official ocaml list (the seniors'
one) can be found at http://caml.inria.fr
Attachments are banned and you're asked to be polite, avoid
flames etc.
Yahoo! Groups Links
<*> To visit your group on the web, go to:
http:/
/groups.yahoo.com/group/ocaml_beginners/
<*> To unsubscribe from this group, send an email to:
ocaml_beginners-unsubscribe@yahoogroups.com
<*> Your use of Yahoo! Groups is subject to:
http://docs.yahoo.c
om/info/terms/
|
|
| "ocaml_beginners"::[] how to
obtain an unsigned int32? |

|
2006-06-22 10:20:19 |
On Thu, Jun 22, 2006 at 11:50:06AM +0200, julien.michel etu.univ-orleans.fr wrote:
> Hi all,
>
> I currently work on an embedded system which has native
32 bits integers. I have
> some trouble with int in caml because their signed
ones.
> I would like to know if there is an easy way to get an
Unsigned int of 32 bits
> format with Caml ?
[...]
Did you tried Nativeint-module?
Ciao,
Oliver
------------------------ Yahoo! Groups Sponsor
--------------------~-->
Check out the new improvements in Yahoo! Groups email.
http://us.click.yahoo.com/6pRQfA/fOaOAA/yQLSAA/saFolB/TM
------------------------------------------------------------
--------~->
Archives up to August 22, 2005 are also downloadable at http://www.connettivo.net/cntprojects/ocaml_beginners/
The archives of the very official ocaml list (the seniors'
one) can be found at http://caml.inria.fr
Attachments are banned and you're asked to be polite, avoid
flames etc.
Yahoo! Groups Links
<*> To visit your group on the web, go to:
http:/
/groups.yahoo.com/group/ocaml_beginners/
<*> To unsubscribe from this group, send an email to:
ocaml_beginners-unsubscribe@yahoogroups.com
<*> Your use of Yahoo! Groups is subject to:
http://docs.yahoo.c
om/info/terms/
|
|
| "ocaml_beginners"::[] how to
obtain an unsigned int32? |

|
2006-06-22 11:46:44 |
Selon Oliver Bandel <oliver first.in-berlin.de>:
> On Thu, Jun 22, 2006 at 11:50:06AM +0200,
julien.michel etu.univ-orleans.fr
> wrote:
> > Hi all,
> >
> > I currently work on an embedded system which has
native 32 bits integers. I
> have
> > some trouble with int in caml because their signed
ones.
> > I would like to know if there is an easy way to
get an Unsigned int of 32
> bits
> > format with Caml ?
> [...]
>
> Did you tried Nativeint-module?
>
>
> Ciao,
> Oliver
>
>
I didn't try the Nativeint module because it provides
operations of SIGNED
32-bit integers (on 32-bit platforms) or signed 64-bit
integers (on 64-bit
platforms) ... whereas I am looking for Unsigned 32bit
integers.
------------------------ Yahoo! Groups Sponsor
--------------------~-->
Great things are happening at Yahoo! Groups. See the new
email design.
http://us.click.yahoo.com/TISQkA/hOaOAA/yQLSAA/saFolB/TM
------------------------------------------------------------
--------~->
Archives up to August 22, 2005 are also downloadable at http://www.connettivo.net/cntprojects/ocaml_beginners/
The archives of the very official ocaml list (the seniors'
one) can be found at http://caml.inria.fr
Attachments are banned and you're asked to be polite, avoid
flames etc.
Yahoo! Groups Links
<*> To visit your group on the web, go to:
http:/
/groups.yahoo.com/group/ocaml_beginners/
<*> To unsubscribe from this group, send an email to:
ocaml_beginners-unsubscribe@yahoogroups.com
<*> Your use of Yahoo! Groups is subject to:
http://docs.yahoo.c
om/info/terms/
|
|
| "ocaml_beginners"::[] how to
obtain an unsigned int32? |

|
2006-06-22 11:56:54 |
Does it really matter? Arithmetic and bitwise operations on
signed &
unsigned numbers are identical with 2s complement iirc (not
sure about
multiplication/division), so the only problem comes with a)
specifying
constants that are larger than the maximum int value as a
signed
number (converting to a signed number would work around it,
though not
exactly pretty), and b) printing them out.
One possibility might be to use camlp4 to let you imagine
you're
dealing with unsigned numbers (from the POV of things like
constants),
and use int64 as a hack-around for printing them out etc.
------------------------ Yahoo! Groups Sponsor
--------------------~-->
Yahoo! Groups gets a make over. See the new email design.
http://us.click.yahoo.com/XISQkA/lOaOAA/yQLSAA/saFolB/TM
------------------------------------------------------------
--------~->
Archives up to August 22, 2005 are also downloadable at http://www.connettivo.net/cntprojects/ocaml_beginners/
The archives of the very official ocaml list (the seniors'
one) can be found at http://caml.inria.fr
Attachments are banned and you're asked to be polite, avoid
flames etc.
Yahoo! Groups Links
<*> To visit your group on the web, go to:
http:/
/groups.yahoo.com/group/ocaml_beginners/
<*> To unsubscribe from this group, send an email to:
ocaml_beginners-unsubscribe@yahoogroups.com
<*> Your use of Yahoo! Groups is subject to:
http://docs.yahoo.c
om/info/terms/
|
|
| "ocaml_beginners"::[] how to
obtain an unsigned int32? |

|
2006-06-22 18:26:52 |
On Thu, 22 Jun 2006, Jonathan Roewen wrote:
> Does it really matter? Arithmetic and bitwise
operations on signed &
> unsigned numbers are identical with 2s complement iirc
(not sure about
> multiplication/division), so the only problem comes
with a) specifying
> constants that are larger than the maximum int value as
a signed
> number (converting to a signed number would work around
it, though not
> exactly pretty), and b) printing them out.
>
> One possibility might be to use camlp4 to let you
imagine you're
> dealing with unsigned numbers (from the POV of things
like constants),
> and use int64 as a hack-around for printing them out
etc.
There's actually a specific syntax that can be used in the
current
version of OCaml. It is documented in the reference manual,
in the
"language extensions" section (yeah, you have to
read the whole manual
before you find whether some feature exists or not).
For 32-bit ints (Int32, not Nativeint!), you just add an l:
# -123l;;
- : int32 = -123l
For the printing problem, Printf provides some adequate
formatters:
# let x = -123l;;
val x : int32 = -123l
# Printf.printf "signed: %li unsigned: %lu\n"
x x;;
signed: -123 unsigned: 4294967173
- : unit = ()
Martin
--
Martin Jambon, PhD
http://martin.jambon.fre
e.fr
Edit http://wikiomics.org,
bioinformatics wiki
------------------------ Yahoo! Groups Sponsor
--------------------~-->
Something is new at Yahoo! Groups. Check out the enhanced
email design.
http://us.click.yahoo.com/SISQkA/gOaOAA/yQLSAA/saFolB/TM
------------------------------------------------------------
--------~->
Archives up to August 22, 2005 are also downloadable at http://www.connettivo.net/cntprojects/ocaml_beginners/
The archives of the very official ocaml list (the seniors'
one) can be found at http://caml.inria.fr
Attachments are banned and you're asked to be polite, avoid
flames etc.
Yahoo! Groups Links
<*> To visit your group on the web, go to:
http:/
/groups.yahoo.com/group/ocaml_beginners/
<*> To unsubscribe from this group, send an email to:
ocaml_beginners-unsubscribe@yahoogroups.com
<*> Your use of Yahoo! Groups is subject to:
http://docs.yahoo.c
om/info/terms/
|
|
[1-5]
|
|