New topic: 

bits and bytes help

<http://forums.realsoftware.com/viewtopic.php?t=38698>

         Page 1 of 1
   [ 2 posts ]                 Previous topic | Next topic          Author  
Message        tpolson          Post subject: bits and bytes helpPosted: Tue 
Apr 19, 2011 9:37 pm                         
Joined: Fri Oct 07, 2005 11:03 pm
Posts: 29                i could use some basic help with a binary file in 
Windows 7.  

I open the file as LittleEndian=True and with ReadfromFile.Position find this 
UInt32 value &h14E00128.  First this is transposed because in a hex editor it 
shows as 2801E014. 

What I need to get is the integer value of the horizontal size, vertical size 
and frame rate from &h14E00128 based on the bit scheme below.  The horizontal 
value should be 640 and vertical value should be 480.  

Horizontal size is 8 bits of byte 4 and 4 bits of byte 5, vertical size is the 
remaining 4 bits of byte 5 and all of byte 6. aspect is half byte 7 and the 
frame rate is the other half of byte 7.

byte 4-----byte 5-----byte 6-----byte 7
76543210 76543210 76543210 76543210
-----------------|----------------| |---|---|
horizontal size_vertical size___AR__FR

I'm sure this is pretty easy, but I've never been able wrap my head around bit 
masking and endian issues.

Any help is greatly appreciated.

Thanks   
                             Top                goomoo          Post subject: 
Re: bits and bytes helpPosted: Wed Apr 20, 2011 1:22 am                         
        
Joined: Sun Aug 22, 2010 10:27 pm
Posts: 61                Code:
Function GetFrameSizeEtc(mb as MemoryBlock, offset as integer,byref hSize as 
integer, byref VSize as integer, byref ar as integer,byref fr as integer) As 
Boolean
  
  if mb.Size-4<offset then return false
  
  dim b1 as byte,b2 as byte
  
  'get horizontal size
  b1=mb.Byte(offset)
  b2=mb.Byte(offset+1)
  
  b2=b2 and &b11110000
  
  b2=Bitwise.ShiftRight(b2,4)
  
  hSize=b2*256+b1
  
  'get vertical size
  b1=mb.Byte(offset+1)
  b2=mb.Byte(offset+2)
  
  b1=b1 and &b00001111
  VSize=b1*256+b2
  
  'get ar
  b1=mb.Byte(offset+3)
  b2=b1 and &b11110000
  b2=Bitwise.ShiftRight(b2,4)
  ar=b2
  
  'get fr
  b2=b1 and &b00001111
  fr=b2
  
  return true  
End Function




By the way, is it a SWF file?      
_________________
Zero-Null-Bit Software.  
MySQL Code Generator for RealBasic: http://rb.znb.cc  
                             Top            Display posts from previous: All 
posts1 day7 days2 weeks1 month3 months6 months1 year Sort by AuthorPost 
timeSubject AscendingDescending          Page 1 of 1
   [ 2 posts ]      
-- 
Over 1500 classes with 29000 functions in one REALbasic plug-in collection. 
The Monkeybread Software Realbasic Plugin v9.3. 
http://www.monkeybreadsoftware.de/realbasic/plugins.shtml

[email protected]

Reply via email to