From: Xavier Leroy <Xavier.Leroy@inria.fr>
To: Bomshik Kim <bskim@ropas.kaist.ac.kr>, caml-list@inria.fr
Subject: Re: How can I treat bits?
Date: Fri, 1 Sep 2000 10:20:48 +0200 [thread overview]
Message-ID: <20000901102048.28072@pauillac.inria.fr> (raw)
In-Reply-To: <Pine.GSO.4.10.10008312210560.10363-100000@ropas.kaist.ac.kr>; from Bomshik Kim on Thu, Aug 31, 2000 at 10:13:14PM +0900
> In C language, we can define a variable size as a unit of bits.
> For example, "unsigned int a:1 ;", " unsigned int b:4 ;" ....
> "colon" is used to set up the number of bits.
>
> Can I define OCaml-variables in the same way?
No, you can't. The smallest unit for data representations is the
machine word. You can also work at the level of bytes by using
strings as byte arrays.
> Because I want to make some data header by using bits as little as
> possible.
> the style that I imagine is...
> type hd = { flag : int_1 ; on_off : int_1 ; seq_num : int_4 } ;;
> let header = { flag = 1 ; on_off = 0 ; seq_num = 0101 } ;;
The best you could do is represent hd as an integer and define
constructor and accessors yourself:
type hd = int
let make_hd flag on_off seq_num =
flag lor (on_off lsl 1) lor (seq_num lsl 2)
let flag_hd h = h land 1
let on_off_hd h = (h lsr 1) land 1
let seq_num_hd h = (h lsr 2) land 0xF
- Xavier Leroy
prev parent reply other threads:[~2000-09-01 8:49 UTC|newest]
Thread overview: 2+ messages / expand[flat|nested] mbox.gz Atom feed top
2000-08-31 13:13 Bomshik Kim
2000-09-01 8:20 ` Xavier Leroy [this message]
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20000901102048.28072@pauillac.inria.fr \
--to=xavier.leroy@inria.fr \
--cc=bskim@ropas.kaist.ac.kr \
--cc=caml-list@inria.fr \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox