<html><head><meta http-equiv="Content-Type" content="text/html; charset=UTF-8"></head><body ><div><div></div><div>Thanks Dave. That's what I need. Haven't tried it, but it seems the solution to our problem. Thanks again. </div><div><br></div><div>Azka</div><div><br></div><div><br></div><div><div style="font-size:75%;color:#575757">Sent from Samsung Mobile</div></div></div><br><br><br>-------- Original message --------<br>From: "David T. Lewis" <lewis@mail.msen.com> <br>Date: 06/12/2013 05:40 (GMT+05:00) <br>To: "A friendly place to get answers to even the most basic questions about        Squeak." <beginners@lists.squeakfoundation.org> <br>Subject: Re: [Newbies] Unsigned interpretation <br> <br><br>On Thu, Dec 05, 2013 at 11:05:15PM +0500, Azka Niazi wrote:<br>> Is there a preexisting method in Squeak 2.8 or 4.1 which can interpret a binary number as an unsigned number?<br>> Thanks,Azka                                            <br><br>Hi Azka,<br><br>I am assuming that you are interested in treating some binary data as an<br>unsigned integer value, and you want to read that data and convert it into<br>a positive integer in Smalltalk.<br><br>The easiest way to do this is to read the binary data into a Smalltalk<br>ByteArray, and then convert that ByteArray into an integer value. Let's<br>assume that the binary data is 32 bits in length (4 bytes), which is a<br>common format. And let's also assume that the binary data was stored in<br>"little endian" format, which is the convention used by most PC computers<br>today.<br><br>It just so happens that the first four bytes of a Squeak image file are an<br>unsigned integer value that identifies what kind of image it is (there are<br>various versions, so the Squeak virtual machine needs to know this in order<br>to load an image file). So using this as an example, here is how to read<br>the first four bytes of a Squeak image file and convert it into a positive<br>integer in Smalltalk:<br><br> fs := FileStream readOnlyFileNamed: Smalltalk imageName. "Open the image file"<br> fs binary. "Set it to binary mode so you get a ByteArray when you read from it"<br> [someBytes := fs next: 4] ensure: [fs close]. "Read the first four bytes into a ByteArray"<br> anUnsignedInteger := someBytes unsignedLongAt: 1 bigEndian: false. "Convert it to Integer"<br> anUnsignedInteger inspect.<br><br>If you evaluate this in a workspace, you will see the integer value of<br>the image format number for that Squeak image file. It will be either 6504<br>or 6505, depending on which VM had been used to save the image file.<br><br>If you look at class ByteArray in category 'platform independent access'<br>you will also find a few other methods for converting binary data into<br>integer and floating point values.<br><br>HTH,<br>Dave<br><br><br>_______________________________________________<br>Beginners mailing list<br>Beginners@lists.squeakfoundation.org<br>http://lists.squeakfoundation.org/mailman/listinfo/beginners<br></body>