* Computing checksum for Ada newbie
@ 2001-08-28 15:11 mop
2001-08-28 16:43 ` tmoran
2001-08-29 8:46 ` John McCabe
0 siblings, 2 replies; 3+ messages in thread
From: mop @ 2001-08-28 15:11 UTC (permalink / raw)
I've got two types - we'll call them TYPE_1, TYPE_2.
The checksum (last byte) for TYPE_1 is the byte eight.
The checksum (last byte) for TYPE_2 varies (depends on user parameters) but
the threshold is byte 517.
The checksum is a simple sum of the the bytes (dont care about overflow)
An example of TYPE_1 is provided. "BYTE" is defined in my package.
type TYPE_1 is
record
XX : BYTE; -- first byte
YY : BYTE; -- second byte
-- etc
Checksum : BYTE; -- eighth byte
end record;
I want a function - we'll call it Compute_Checksum that'll sum the bytes
function Compute_Checksum return BYTE is -- dont think this is right. need
to pass in which type
INTEGER : Checksum :=0;
begin
-- more help here
end Compute_Checksum;
^ permalink raw reply [flat|nested] 3+ messages in thread
* Re: Computing checksum for Ada newbie
2001-08-28 15:11 Computing checksum for Ada newbie mop
@ 2001-08-28 16:43 ` tmoran
2001-08-29 8:46 ` John McCabe
1 sibling, 0 replies; 3+ messages in thread
From: tmoran @ 2001-08-28 16:43 UTC (permalink / raw)
Do you mean something like:
type BYTE is mod 256; -- ignore overflow
type TYPE_1 is
record
XX : BYTE; -- first byte
YY : BYTE; -- second byte
Third, Fourth, Fifth, Sixth, Seventh : BYTE;
Checksum : BYTE; -- eighth byte
end record;
function Compute_Checksum(X : in TYPE_1) return BYTE is
begin
return X.Checksum;
end Compute_Checksum;
or perhaps
function Compute_Checksum(X : in TYPE_1) return BYTE is
begin
return X.XX+X.YY+X.Third+X.Fourth+X.Fifth+X.Sixth+X.Seventh;
end Compute_Checksum;
or perhaps
procedure Compute_Checksum(X : in out TYPE_1) is
begin
X.Checksum := X.XX+X.YY+X.Third+X.Fourth+X.Fifth+X.Sixth+X.Seventh;
end Compute_Checksum;
and similarly for TYPE_2, etc.
^ permalink raw reply [flat|nested] 3+ messages in thread
* Re: Computing checksum for Ada newbie
2001-08-28 15:11 Computing checksum for Ada newbie mop
2001-08-28 16:43 ` tmoran
@ 2001-08-29 8:46 ` John McCabe
1 sibling, 0 replies; 3+ messages in thread
From: John McCabe @ 2001-08-29 8:46 UTC (permalink / raw)
On Tue, 28 Aug 2001 11:11:47 -0400, "mop"
<mop65715@pegasus.cc.ucf.edu> wrote:
>I've got two types - we'll call them TYPE_1, TYPE_2.
>
>The checksum (last byte) for TYPE_1 is the byte eight.
>The checksum (last byte) for TYPE_2 varies (depends on user parameters) but
>the threshold is byte 517.
>The checksum is a simple sum of the the bytes (dont care about overflow)
>An example of TYPE_1 is provided. "BYTE" is defined in my package.
>
>type TYPE_1 is
>record
> XX : BYTE; -- first byte
> YY : BYTE; -- second byte
>-- etc
> Checksum : BYTE; -- eighth byte
>end record;
>
>I want a function - we'll call it Compute_Checksum that'll sum the bytes
>
>function Compute_Checksum return BYTE is -- dont think this is right. need
>to pass in which type
> INTEGER : Checksum :=0;
>begin
>-- more help here
>end Compute_Checksum;
>
>
It's not 100% clear what you require here, but I would probably use
unchecked conversion of the record into a packed array of bytes then
calculate the checksum in a loop. Some people might consider this
cheating, but ... :-)
Best Regards
John McCabe
^ permalink raw reply [flat|nested] 3+ messages in thread
end of thread, other threads:[~2001-08-29 8:46 UTC | newest]
Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2001-08-28 15:11 Computing checksum for Ada newbie mop
2001-08-28 16:43 ` tmoran
2001-08-29 8:46 ` John McCabe
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox