Re: SDL-News: How to represent bytes?


Subject: Re: SDL-News: How to represent bytes?
From: Rick Reed TSE (rickreed#tseng.co.uk)
Date: Fri May 30 2003 - 16:43:55 GMT


Become an SDL Forum Society member <http://www.sdl-forum.org/Society/members.htm>
The originator of this message is responsible for its content.
-----From Rick Reed TSE <rickreed#tseng.co.uk> to sdlnews -----

Dhillon, Harry S (Harry) at hdhillon#lucent.com wrote on 30/05/2003 15:08:

> Hi. I used SDL a long time back and am just re-examining it.
> I wanted to know if/how bytes could be represented (e.g.,
> for interfacing with an embedded application)?
>
> Is it possible to specify a byte as an abstract data type,
> with associated operations?
>
> Do current SDL tools support such an ADT or must it
> always be user-defined?
>
> Any thoughts would be appreciated.
>
> Regards,
> Harry

Dear Harry,

The most appropriate data types are Octet and Octetstring.

These are language defined and (therefore) supported by tools.

More detail
___________

An Octet is a Bitstring SIZE(8) -- that is a string of exactly 8 bits.
Bitstring is defined as a "string" of elements of type Bit.
Bit has the values denoted by 0 and 1.
Bit is actually defined as a new data type based on the Boolean data type,
However, Boolean is often implemented as more than one bit, and although SDL
does not (at present) require any particular encoding of the data type Bit,
it should be obvious that Bit (at least in Bitstring) should be implemented
as a single bit.

However, a word of warning. Whereas a data type defined using String is
always indexed from 1, to be compatible with ASN.1 Bitstring is indexed from
0 (zero).

From the language definitions Bit has the same operators as Boolean:

"not"(Bit) -> Bit; /* a prefix operator for example NOT 1) */
"and"(Bit,Bit)->Bit; /* an infix operator for example 1 AND 0 */
"or"(Bit,Bit)->Bit; /* an infix operator for example 1 OR 0 */
"xor"(Bit,Bit)->Bit; /* an infix operator for example 1 XOR 0 */
"=>"(Bit,Bit)->Bit; /* the implies infix operator for example 1 => 0 */

and (as every data type)

"="(Bit,Bit)->Boolean;
"/="(Bit,Bit)->Boolean;

and the additional operators

num(Bit)->Integer; /* where num(0)=0, num(1)= 1*/
bit(Integer) -> Bit; /* where bit(0)=0, bit(1)= 1
                        and bit(x) where x<0 or x>1 raises an exception */
An Octetstring is defined as String<Octet>
(or in SDL-96 notation String(Octet) ).
and therefore inherits all the operators defined for String.

Bitstring and Octetstring have the operators:

length - gives the length of the string as an integer.
first - first element of the string
last - last element of the string
// - infix operator to concatenate two strings
Extract - get the ith element of the string - exception if invalid index
Modify - change ith element of string - exception if invalid index
substring - string length j starting at ith element - exception if invalid
remove - delete j elements starting at ith element

In addition (as for all data types based on String), you can use the
notation s(i) to refer to the ith element of string s, both in expressions
and on the left side of an assignment.

Bitstring has additional logical infix operators: NOT, AND, OR, XOR and =>
and the operators:
num(Bitstring)-> Integer;
bitstring(Integer)-> Bitstring; /* negative Integers give Out of Range */
octet(Integer) -> Bitstring; /* 0 to 255 gives Bitstring SIZE(8)
                                other Integers are Out of Range */

For the Bitstring logical operators, if the two string are of different
lengths the shortest string is extended to the right with zeros.

Octetstring does not have logical operators defined by the language,
but has two operators:
bitstring(Octetstring)->Bitstring;
octetstring(Bitstring)->Octetstring;
A Bitstring that is made into an Octetstring is extended to the right with
zeros if necessary to make it an exact multiple of 8 bits.

The ASN.1 notations for Bitstring and Octetstring values of the form
'0101111'B and 'AF'H are not supported in SDL in all tools and some tool
specific operators are provided. Check tool documentation for these and
support of the above operators.

--
Rick Reed - rickreed#tseng.co.uk
Tel:+44 15394 88462 Mob.:+44 7970 50 96 50

--End text from Rick Reed TSE <rickreed#tseng.co.uk> to sdlnews --- For extra SDL Forum Society benefits join at <http://www.sdl-forum.org/Society/members.htm>



This archive was generated by hypermail 2a23 : Thu May 09 2013 - 16:05:49 GMT