Contents
Articles
Behaviors
Books
Director News
Director Web Sites
FAQ
Games
Mailing Lists
News Groups
Project Examples
Reviews
Software
Tools
Useful Web Sites
Utilities
Xtras

Don't miss these
Vector Shape - Create Square Wave
Media Make & Go
simComportIOCP Xtra
Check QuickTime Version
Set CommonPlayer properties for Director 2004
Help Studio 2000
DateTimeXtra
cXtraRTF
Vim Scripts for Lingo
Swap Language Cast Libraries
 

 

 

Behavior Binary Opperations

Added on 3/2/2003

 

Compatibilities:
D7 D8 D8_5 D9 Mac PC Script Shockwave

Rating:

Author: MediaMacros (website)

Director does not have proper bitshift left and right, binary to integer conversion or integer to binary string conversion. These handlers get around this.

--Copyright 2003, Chuck Neal
--MediaMacros, Inc.

on getBinary vNum, vDepth
  if vDepth = void then vDepth = 32
  baseNums = ["0","1"]
  n = ""
  neg = 0
  if vnum < 0 then
    neg = 1
    vnum = integer(the maxInteger + 1.0 + vNum)
  end if  
  vNum = integer(vNum)
  repeat while vNum
    nMod = vNum mod 2
    put string(baseNums[nMod + 1]) before n
    vNum = vNum / 2
  end repeat
  --add preceeding 0
  repeat while n.char.count < vDepth - 1
    put "0" before n
  end repeat
  if n.char.count < vDepth then
   put neg before n
    end if
    return n
end

on getInt vBinary
  baseNums = ["0","1"]
  if vBinary.char[1] = "1" then negative = 1
  nConverted = 0
  nMax = vBinary.length
  repeat with nIndex = 1 to nMax
    nConverted = nConverted * 2
    nConverted = nConverted + baseNums.getOne(vBinary.char[nIndex]) - 1
  end repeat  
  return nConverted  
end

on bitShiftLeft vNum, vShift, vDepth
  --return integer((vNum * (power(2,vShift))) - .5)
  if vDepth = void then vDepth = 32
  iBinary = getBinary(vNum, vDepth)
  --get a positive value
  vShift = min(32, abs(vShift))
  nBinary = iBinary.char[(vShift + 1)..vDepth] --& iBinary.char[1..vShift]
  --pad with zeros
  repeat while nBinary.char.count < vDepth
    put "0" after nBinary
  end repeat
  
  nNumber = getInt(nBinary)
  return nNumber
end

on bitShiftRight vNum, VShift, vDepth
  if vDepth = void then vDepth = 32
  iBinary = getBinary(vNum, vDepth)
  --get a positive value
  vShift = min(vDepth, abs(vShift))
  nBinary = iBinary.char[1..(vDepth - vShift)]
  repeat while nBinary.char.count < vDepth
    put nBinary.char[1] before nBinary  
  end repeat
  nNumber = getInt(nBinary)
  return nNumber
end

on bitShiftRightZeroFill vNum, vShift, vDepth
  if vDepth = void then vDepth = 32
  iBinary = getBinary(vNum, vDepth)
  --get a positive value
  vShift = min(vDepth, abs(vShift))
  nBinary = iBinary.char[1..(vDepth - vShift)]
  repeat while nBinary.char.count < vDepth
  put "0" before nBinary  
  end repeat
    nNumber = getInt(nBinary)
  return nNumber
end

 


Contact

MMI
36 South Court Sq
Suite 300
Newnan, GA 30263
USA

Send e-mail