Mathematica 9 is now available
Services & Resources / Wolfram Forums
-----
 /
MathGroup Archive
2006
*January
*February
*March
*April
*May
*June
*July
*August
*September
*October
*November
*December
*Archive Index
*Ask about this page
*Print this page
*Give us feedback
*Sign up for the Wolfram Insider

MathGroup Archive 2006

[Date Index] [Thread Index] [Author Index]

Search the Archive

Re: Binaries

  • To: mathgroup at smc.vnet.net
  • Subject: [mg69763] Re: Binaries
  • From: dh <dh at metrohm.ch>
  • Date: Fri, 22 Sep 2006 01:04:43 -0400 (EDT)
  • References: <eetuj3$9ls$1@smc.vnet.net>

Hi David,
your question is not too clear. To you want to read from a file or do 
you want to convert from an n bits integer? What do you exactly mean by 
long: 32, 64, 128 bits?
Further, I assume you are talking about integers. Now do the three bytes 
repesent 1 or 3 numbers?

1) Assuming the three bytes code for one number and the long has 32 bits 
and you want to read from a file. In this case, you can simply read the 
whole 32 integer by:
BinaryReadList[stream,"Integer32"];
see manual
2) If the three bytes are 3 different numbers, and you want to read from 
a file written with 32 bits integres, you need to read every single byte 
and throw away the superfluos byte:
t=BinaryReadList[stream,"Integer8"]
t=Partition[t,4];
t=Drop[t,{},1]

3) In case you want to convert Integers, you may use Bit Operators like 
BitAnd,BitOr,.. ,see manual or: Developer`BitShiftLeft/Right

Daniel

David.MartinyMarero at uam.es wrote:
> Dear sirs,
> 
> How can I read binary numbers with the format: three bytes placed in a
> long?
> 
> Thanks,
> 
> D-
> 


  • Prev by Date: Re: TEXT SIZE 12 ?
  • Next by Date: Off[General::spell1] and StyleSheet Notepad
  • Previous by thread: Re: Binaries
  • Next by thread: Programming in Mathematica