# [VW 7.1] Binary Coded Decimal

4 messages
Open this post in threaded view
|

## [VW 7.1] Binary Coded Decimal

 Hi ,Visualworks [7.1 ?] has some library class/method that supports reading and writing of Binary coded decimals ? What do you suggest as a better approach for implementing this requirement? Another not so important question is,ByteArray has indexedType #bytes, but its elements are Integer, so why is it not indexed as #objects ? Also, how does smalltalk handle a data of exactly 1 byte? (a ByteArray with only one element?) What is the easiest way to convert it (the byte) to bits?(#printStringRadix:2  ??) Thanks in advance,Mani _______________________________________________ vwnc mailing list [hidden email] http://lists.cs.uiuc.edu/mailman/listinfo/vwnc
Open this post in threaded view
|

## Re: [VW 7.1] Binary Coded Decimal

 Mani,   This example creates a ByteArray of the bytes of a double and then converts it back to a double:   | d b | d := 383.323d. b := ByteArray new: d basicSize. 1 to: b size do: [:i | b at: i put: (d basicAt: i) ]. b changeClassTo: d class. b   383.323d   An #object type is is a pointer to another object, and each pointer takes far more than eight bits to implement. Smalltalk handles data of 1 byte by having a ByteArray of size 1 (there is no Byte object just as there is no Bit object). Bit operations are done on integers, and the bytearray representation is a collection of integers. If you need to do bit operations then do them on the integer(s) and not to a string of characters produced from something like #printStringRadix:. If you need to do bit operations on the entire contents then you might use a trick of forming an integer from the contents (instead of the ByteArray in the earlier example):   | d b | d := 383.323d. b := LargePositiveInteger basicNew: d basicSize. 1 to: b basicSize do: [:i | b digitAt: i put: (d basicAt: i) ]. b   4645451105722714554   Both ByteArray and LargePositiveInteger are byte structures. LPI just implements behavior that may be more useful to you for bit operations. The #changeClassTo: trick works for LPI instances too. I don't recall if you'd need to be concerned with endian transformations with tricks like these.   Paul Baumann       From: [hidden email] [mailto:[hidden email]] On Behalf Of mani kartha Sent: Tuesday, March 18, 2014 04:50 To: [hidden email] Subject: [vwnc] [VW 7.1] Binary Coded Decimal   Hi , Visualworks [7.1 ?] has some library class/method that supports reading and writing of Binary coded decimals ? What do you suggest as a better approach for implementing this requirement? Another not so important question is, ByteArray has indexedType #bytes, but its elements are Integer, so why is it not indexed as #objects ? Also, how does smalltalk handle a data of exactly 1 byte? (a ByteArray with only one element?) What is the easiest way to convert it (the byte) to bits?(#printStringRadix:2  ??) Thanks in advance, Mani   This message may contain confidential information and is intended for specific recipients unless explicitly noted otherwise. If you have reason to believe you are not an intended recipient of this message, please delete it and notify the sender. This message may not represent the opinion of IntercontinentalExchange, Inc. (ICE), its subsidiaries or affiliates, and does not constitute a contract or guarantee. Unencrypted electronic mail is not secure and the recipient of this message is expected to provide safeguards from viruses and pursue alternate means of communication where privacy or a binding message is desired. _______________________________________________ vwnc mailing list [hidden email] http://lists.cs.uiuc.edu/mailman/listinfo/vwnc