* crc and Ada @ 2003-05-18 7:04 Bartłomiej Ś. 2003-05-18 7:27 ` John R. Strohm ` (5 more replies) 0 siblings, 6 replies; 8+ messages in thread From: Bartłomiej Ś. @ 2003-05-18 7:04 UTC (permalink / raw) Hello, I'm starting in Ada, and I can't use same operators (like xor, and) in my programs. I need to count crc. In Java I was writting: #v+ ... crc=(crctable[((crc>>8)^bufor[start+i++]) & 0xFF]^(crc<<8))&0xFFFF; ... #v- What I should use instand of 'xor' and 'and' oparator (becouse in Ada they are logical oparator, not binary). For example, I replace crc<<8 by crc*256, and crc>>8 crc/256, but what about xor? -- Best regards, PGP: http://wilk.wpk.p.lodz.pl/swierczu/pgp Bartek. http://sknauk.wpk.p.lodz.pl ^ permalink raw reply [flat|nested] 8+ messages in thread
* Re: crc and Ada 2003-05-18 7:04 crc and Ada Bartłomiej Ś. @ 2003-05-18 7:27 ` John R. Strohm 2003-05-18 7:38 ` Martin Krischik ` (4 subsequent siblings) 5 siblings, 0 replies; 8+ messages in thread From: John R. Strohm @ 2003-05-18 7:27 UTC (permalink / raw) [-- Warning: decoded text below may be mangled, UTF-8 assumed --] [-- Attachment #1: Type: text/plain, Size: 1310 bytes --] "Bart�omiej �." <swierczu@wpk.p.lodz.pl> wrote in message news:slrnbcec3j.rh.swierczu@staticline881.toya.net.pl... > Hello, > I'm starting in Ada, and I can't use same operators (like xor, and) in > my programs. I need to count crc. In Java I was writting: > #v+ > ... > crc=(crctable[((crc>>8)^bufor[start+i++]) & 0xFF]^(crc<<8))&0xFFFF; > ... > #v- > What I should use instand of 'xor' and 'and' oparator (becouse in Ada > they are logical oparator, not binary). For example, I replace crc<<8 by > crc*256, and crc>>8 crc/256, but what about xor? Check your compiler documentation. They MAY export a machine intrinsics package, which contains bitwise AND, OR, XOR, and such. Check your compiler documentation. Look for assembly language interfacing. You certainly could write a little routine in assembly language that XOR'ed two arguments and returned the result, and then hook it up to the Ada. Also check your compiler documentation, for information about machine code insertions. CAUTION: Machine code insertions in Ada are NOT something a novice should be tackling, but, occasionally, for political reasons, you can get management approval for a machine code insertion where you couldn't get approval for an assembly language subroutine. (Been there, done that, didn't WANT the T-shirt.) ^ permalink raw reply [flat|nested] 8+ messages in thread
* Re: crc and Ada 2003-05-18 7:04 crc and Ada Bartłomiej Ś. 2003-05-18 7:27 ` John R. Strohm @ 2003-05-18 7:38 ` Martin Krischik 2003-05-18 7:49 ` Martin Dowie ` (3 subsequent siblings) 5 siblings, 0 replies; 8+ messages in thread From: Martin Krischik @ 2003-05-18 7:38 UTC (permalink / raw) Bart?omiej ?. wrote: > Hello, > What I should use instand of 'xor' and 'and' oparator (becouse in Ada > they are logical oparator, not binary). "xor" and "and" are not only boolean operators. They can be used with several datatypes. Also you can also define your own "xor" and "and" operators. > For example, I replace crc<<8 by > crc*256, and crc>>8 crc/256, but what about xor? I belive that in your case (crc calculation) a modular datatype (which have predefined "xor", "and", "or" and "not" operators) might be alternative. i.E. type Unsigned_Byte is mod 2**8; type Unsigned_Short is mod 2**16; type Unsigned_Long is mod 2**32; you might want to add a representation clause (if you don't trust the compiler to make the right choice): for Unsigned_Byte'Size use 8; for Unsigned_Short'Size use 16; for Unsigned_Long'Size use 32; Remember that for a modular type wrap arount arithmetic (which for a CRC calculation is probably what you want) is used. i.E. Zero_Byte : Unsigned_Byte := 255 + 1; Disclainer: This might not compile, it's just to show the general idea. With Regarda Martin > -- > Best regards, PGP: http://wilk.wpk.p.lodz.pl/swierczu/pgp > Bartek. http://sknauk.wpk.p.lodz.pl -- -- mailto://krischik@users.sourceforge.net http://www.ada.krischik.com ^ permalink raw reply [flat|nested] 8+ messages in thread
* Re: crc and Ada 2003-05-18 7:04 crc and Ada Bartłomiej Ś. 2003-05-18 7:27 ` John R. Strohm 2003-05-18 7:38 ` Martin Krischik @ 2003-05-18 7:49 ` Martin Dowie 2003-05-18 7:56 ` tmoran ` (2 subsequent siblings) 5 siblings, 0 replies; 8+ messages in thread From: Martin Dowie @ 2003-05-18 7:49 UTC (permalink / raw) [-- Warning: decoded text below may be mangled, UTF-8 assumed --] [-- Attachment #1: Type: text/plain, Size: 883 bytes --] "Bart�omiej �." <swierczu@wpk.p.lodz.pl> wrote in message news:slrnbcec3j.rh.swierczu@staticline881.toya.net.pl... > Hello, > I'm starting in Ada, and I can't use same operators (like xor, and) in > my programs. I need to count crc. In Java I was writting: > #v+ > ... > crc=(crctable[((crc>>8)^bufor[start+i++]) & 0xFF]^(crc<<8))&0xFFFF; > ... > #v- > What I should use instand of 'xor' and 'and' oparator (becouse in Ada > they are logical oparator, not binary). For example, I replace crc<<8 by > crc*256, and crc>>8 crc/256, but what about xor? You should check out 'modular types' and the standard package 'Interfaces'. What compiler are you using? If the typical GNAT/AdaGIDE combo these can be found under the Help->Language RM drop-down menu. Also, check out www.adapower.com and the 'Learn Ada' option will take you to link to a few free Ada95 books. Good luck! ^ permalink raw reply [flat|nested] 8+ messages in thread
* Re: crc and Ada 2003-05-18 7:04 crc and Ada Bartłomiej Ś. ` (2 preceding siblings ...) 2003-05-18 7:49 ` Martin Dowie @ 2003-05-18 7:56 ` tmoran 2003-05-18 9:35 ` Bartłomiej Ś. 2003-05-18 8:05 ` Tarjei T. Jensen 2003-05-19 9:09 ` Ludovic Brenta 5 siblings, 1 reply; 8+ messages in thread From: tmoran @ 2003-05-18 7:56 UTC (permalink / raw) > I'm starting in Ada, and I can't use same operators (like xor, and) in Take another look at your Ada text. There are indeed "and", "xor" etc operators for modular (unsigned) types. > crc=(crctable[((crc>>8)^bufor[start+i++]) & 0xFF]^(crc<<8))&0xFFFF; type crc_type is mod 2**16; crc : crc_type := initial value type byte is mod 256; crc_table : array(byte) of crc_type; for i in start .. finish loop crc:=crc_table(byte(crc/256) xor bufor(i)) xor ((crc mod 256)*256); end loop; ^ permalink raw reply [flat|nested] 8+ messages in thread
* Re: crc and Ada 2003-05-18 7:56 ` tmoran @ 2003-05-18 9:35 ` Bartłomiej Ś. 0 siblings, 0 replies; 8+ messages in thread From: Bartłomiej Ś. @ 2003-05-18 9:35 UTC (permalink / raw) W artykule <M0Hxa.878367$3D1.501024@sccrnsc01> tmoran@acm.org napisaďż˝(a): >> I'm starting in Ada, and I can't use same operators (like xor, and) in > Take another look at your Ada text. There are indeed "and", "xor" etc > operators for modular (unsigned) types. > >> crc=(crctable[((crc>>8)^bufor[start+i++]) & 0xFF]^(crc<<8))&0xFFFF; > > type crc_type is mod 2**16; > crc : crc_type := initial value > type byte is mod 256; > crc_table : array(byte) of crc_type; > > for i in start .. finish loop > crc:=crc_table(byte(crc/256) xor bufor(i)) xor ((crc mod 256)*256); > end loop; I was made: #v- function makeCrc (buffor : Stream_Element_Array; start : Stream_Element_Offset; len : Stream_Element_Offset) return Natural is package Output_Integers is new Ada.Text_IO.Modular_IO (Unsigned_32); use Output_Integers; type CRC_Array is array (Unsigned_8) of Unsigned_32; crctable : CRC_Array := ( 16#0000#, 16#C0C1#, 16#C181#, 16#0140#, 16#C301#, 16#03C0#, 16#0280#, 16#C241#, 16#C601#, 16#06C0#, 16#0780#, 16#C741#, 16#0500#, 16#C5C1#, 16#C481#, 16#0440#, 16#CC01#, 16#0CC0#, 16#0D80#, 16#CD41#, 16#0F00#, 16#CFC1#, 16#CE81#, 16#0E40#, 16#0A00#, 16#CAC1#, 16#CB81#, 16#0B40#, 16#C901#, 16#09C0#, 16#0880#, 16#C841#, 16#D801#, 16#18C0#, 16#1980#, 16#D941#, 16#1B00#, 16#DBC1#, 16#DA81#, 16#1A40#, 16#1E00#, 16#DEC1#, 16#DF81#, 16#1F40#, 16#DD01#, 16#1DC0#, 16#1C80#, 16#DC41#, 16#1400#, 16#D4C1#, 16#D581#, 16#1540#, 16#D701#, 16#17C0#, 16#1680#, 16#D641#, 16#D201#, 16#12C0#, 16#1380#, 16#D341#, 16#1100#, 16#D1C1#, 16#D081#, 16#1040#, 16#F001#, 16#30C0#, 16#3180#, 16#F141#, 16#3300#, 16#F3C1#, 16#F281#, 16#3240#, 16#3600#, 16#F6C1#, 16#F781#, 16#3740#, 16#F501#, 16#35C0#, 16#3480#, 16#F441#, 16#3C00#, 16#FCC1#, 16#FD81#, 16#3D40#, 16#FF01#, 16#3FC0#, 16#3E80#, 16#FE41#, 16#FA01#, 16#3AC0#, 16#3B80#, 16#FB41#, 16#3900#, 16#F9C1#, 16#F881#, 16#3840#, 16#2800#, 16#E8C1#, 16#E981#, 16#2940#, 16#EB01#, 16#2BC0#, 16#2A80#, 16#EA41#, 16#EE01#, 16#2EC0#, 16#2F80#, 16#EF41#, 16#2D00#, 16#EDC1#, 16#EC81#, 16#2C40#, 16#E401#, 16#24C0#, 16#2580#, 16#E541#, 16#2700#, 16#E7C1#, 16#E681#, 16#2640#, 16#2200#, 16#E2C1#, 16#E381#, 16#2340#, 16#E101#, 16#21C0#, 16#2080#, 16#E041#, 16#A001#, 16#60C0#, 16#6180#, 16#A141#, 16#6300#, 16#A3C1#, 16#A281#, 16#6240#, 16#6600#, 16#A6C1#, 16#A781#, 16#6740#, 16#A501#, 16#65C0#, 16#6480#, 16#A441#, 16#6C00#, 16#ACC1#, 16#AD81#, 16#6D40#, 16#AF01#, 16#6FC0#, 16#6E80#, 16#AE41#, 16#AA01#, 16#6AC0#, 16#6B80#, 16#AB41#, 16#6900#, 16#A9C1#, 16#A881#, 16#6840#, 16#7800#, 16#B8C1#, 16#B981#, 16#7940#, 16#BB01#, 16#7BC0#, 16#7A80#, 16#BA41#, 16#BE01#, 16#7EC0#, 16#7F80#, 16#BF41#, 16#7D00#, 16#BDC1#, 16#BC81#, 16#7C40#, 16#B401#, 16#74C0#, 16#7580#, 16#B541#, 16#7700#, 16#B7C1#, 16#B681#, 16#7640#, 16#7200#, 16#B2C1#, 16#B381#, 16#7340#, 16#B101#, 16#71C0#, 16#7080#, 16#B041#, 16#5000#, 16#90C1#, 16#9181#, 16#5140#, 16#9301#, 16#53C0#, 16#5280#, 16#9241#, 16#9601#, 16#56C0#, 16#5780#, 16#9741#, 16#5500#, 16#95C1#, 16#9481#, 16#5440#, 16#9C01#, 16#5CC0#, 16#5D80#, 16#9D41#, 16#5F00#, 16#9FC1#, 16#9E81#, 16#5E40#, 16#5A00#, 16#9AC1#, 16#9B81#, 16#5B40#, 16#9901#, 16#59C0#, 16#5880#, 16#9841#, 16#8801#, 16#48C0#, 16#4980#, 16#8941#, 16#4B00#, 16#8BC1#, 16#8A81#, 16#4A40#, 16#4E00#, 16#8EC1#, 16#8F81#, 16#4F40#, 16#8D01#, 16#4DC0#, 16#4C80#, 16#8C41#, 16#4400#, 16#84C1#, 16#8581#, 16#4540#, 16#8701#, 16#47C0#, 16#4680#, 16#8641#, 16#8201#, 16#42C0#, 16#4380#, 16#8341#, 16#4100#, 16#81C1#, 16#8081#, 16#4040# ); crc : Unsigned_32 := 0; i : Unsigned_8 := 0; begin while (i<Unsigned_8(len)) loop crc := (crctable( Unsigned_8((crc/256) xor Unsigned_32 (buffor(start+Stream_Element_Offset(i)))) and 16#ff#) xor (crc*256)) and 16#ffff#; i := i + 1; end loop; return Natural(crc); end makeCrc; #v- Thank's for yours opinion and sugestion. -- Pozdrowienia, PGP: http://wilk.wpk.p.lodz.pl/swierczu/pgp Bartek. http://sknauk.wpk.p.lodz.pl ^ permalink raw reply [flat|nested] 8+ messages in thread
* Re: crc and Ada 2003-05-18 7:04 crc and Ada Bartłomiej Ś. ` (3 preceding siblings ...) 2003-05-18 7:56 ` tmoran @ 2003-05-18 8:05 ` Tarjei T. Jensen 2003-05-19 9:09 ` Ludovic Brenta 5 siblings, 0 replies; 8+ messages in thread From: Tarjei T. Jensen @ 2003-05-18 8:05 UTC (permalink / raw) [-- Warning: decoded text below may be mangled, UTF-8 assumed --] [-- Attachment #1: Type: text/plain, Size: 526 bytes --] "Bart�omiej �." wrote: > crc=(crctable[((crc>>8)^bufor[start+i++]) & 0xFF]^(crc<<8))&0xFFFF; > ... > #v- > What I should use instand of 'xor' and 'and' oparator (becouse in Ada > they are logical oparator, not binary). For example, I replace crc<<8 by > crc*256, and crc>>8 crc/256, but what about xor? Read section 4.5.1 of the Ada 95 Reference Manual. and, or and xor is defined for every bolean and modular type. In addtion also single dimentioned arrays of boolean. Also have a look Appendix B.2. greetings,, ^ permalink raw reply [flat|nested] 8+ messages in thread
* Re: crc and Ada 2003-05-18 7:04 crc and Ada Bartłomiej Ś. ` (4 preceding siblings ...) 2003-05-18 8:05 ` Tarjei T. Jensen @ 2003-05-19 9:09 ` Ludovic Brenta 5 siblings, 0 replies; 8+ messages in thread From: Ludovic Brenta @ 2003-05-19 9:09 UTC (permalink / raw) Bartďż˝omiej ďż˝. <swierczu@wpk.p.lodz.pl> writes: > Hello, > I'm starting in Ada, and I can't use same operators (like xor, and) in > my programs. I need to count crc. In Java I was writting: If your compiler is GNAT, there is the package System.CRC32. Look at the sources in lib/gcc-lib/.../.../adainclude/s-crc32.ad{b,s}. There is also an older version of this file at: http://korea.gnu.org/gcc/src/gcc-3.1/gcc/ada/s-crc32.adb http://korea.gnu.org/gcc/src/gcc-3.1/gcc/ada/s-crc32.ads FWIW, consider the following code: type CRC32 is new Interfaces.Unsigned_32; -- Used to represent CRC32 values, which are 32 bit bit-strings procedure Update (C : in out CRC32; Value : Character) is V : constant CRC32 := CRC32 (Character'Pos (Value)); begin C := Shift_Right (C, 8) xor Table (V xor (C and 16#0000_00FF#)); end Update; HTH -- Ludovic Brenta. ^ permalink raw reply [flat|nested] 8+ messages in thread
end of thread, other threads:[~2003-05-19 9:09 UTC | newest] Thread overview: 8+ messages (download: mbox.gz / follow: Atom feed) -- links below jump to the message on this page -- 2003-05-18 7:04 crc and Ada Bartłomiej Ś. 2003-05-18 7:27 ` John R. Strohm 2003-05-18 7:38 ` Martin Krischik 2003-05-18 7:49 ` Martin Dowie 2003-05-18 7:56 ` tmoran 2003-05-18 9:35 ` Bartłomiej Ś. 2003-05-18 8:05 ` Tarjei T. Jensen 2003-05-19 9:09 ` Ludovic Brenta
This is a public inbox, see mirroring instructions for how to clone and mirror all data and code used for this inbox