We help IT Professionals succeed at work.

Javascript pack unpack

mattaustin
mattaustin asked
on
9,220 Views
Last Modified: 2008-01-09
is there a JavaScript function like Perls pack and unpack?
Comment
Watch Question

There isnt any similar to that in javascript!

Commented:
Sorry, sport, but I am WAY not a Perl kind o' guy. Tell me, et al., what pack and unpack do.
ZvonkoSystems architect
CERTIFIED EXPERT
Top Expert 2006

Commented:
You have to tell us your reqirments, and then we can help you.

E.g.:
<script>
function packBin(theNum){
  return theNum.toString(2)
}

alert(packBin(123));
</script>

Author

Commented:
unpack("a4nNnN2a*",$body); is my accual perl code
Pack and unpack make variables into bitstrings of binary data.
ZvonkoSystems architect
CERTIFIED EXPERT
Top Expert 2006

Commented:
Or this:

<script>
function packBin(theNum){
  return theNum.toString(2)
}
function unpackBin(theString){
  return parseInt(theString,2)
}

alert(packBin(123));
alert(unpackBin(packBin(123)));


</script>

ZvonkoSystems architect
CERTIFIED EXPERT
Top Expert 2006

Commented:
Anything with formatstrings will become very complicated, because there are NO formating functions in JavaScript and you have to build them by hand.
ZvonkoSystems architect
CERTIFIED EXPERT
Top Expert 2006
Commented:
This problem has been solved!
(Unlock this solution with a 7-day Free Trial)
UNLOCK SOLUTION
Commented:
This problem has been solved!
(Unlock this solution with a 7-day Free Trial)
UNLOCK SOLUTION

Gain unlimited access to on-demand training courses with an Experts Exchange subscription.

Get Access
Why Experts Exchange?

Experts Exchange always has the answer, or at the least points me in the correct direction! It is like having another employee that is extremely experienced.

Jim Murphy
Programmer at Smart IT Solutions

When asked, what has been your best career decision?

Deciding to stick with EE.

Mohamed Asif
Technical Department Head

Being involved with EE helped me to grow personally and professionally.

Carl Webster
CTP, Sr Infrastructure Consultant
Empower Your Career
Did You Know?

We've partnered with two important charities to provide clean water and computer science education to those who need it most. READ MORE

Ask ANY Question

Connect with Certified Experts to gain insight and support on specific technology challenges including:

  • Troubleshooting
  • Research
  • Professional Opinions