Search content:

 

Personal Menu
Username:
Password:
Save password

Become a member

Forgot Password?

 

Don't miss these
Super Goo
.HLP
27
Show Recordset's Current Record
Toggle ButtonsEnabled Property of a Flash Sprite
cXtraShapeWindow
Back Button
display TreeView
Clean for reinstall
JTMR Digital Painter
MediaMacros Xtras Mall
 

 

 

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

 


Upload Provided by ABCUpload ASP

Contact

MMI
22 West Court Sq
Suite 2C
Newnan, GA 30263
USA

Fax - (206) 339-5833

Send e-mail