Go Back   HowtoForge Forums | HowtoForge - Linux Howtos and Tutorials > Linux Forums > Programming/Scripts

Do you like HowtoForge? Please consider supporting us by becoming a subscriber.
Reply
 
Thread Tools Display Modes
  #1  
Old 15th April 2009, 10:47
rini90 rini90 is offline
Junior Member
 
Join Date: Nov 2008
Location: Germany
Posts: 11
Thanks: 0
Thanked 1 Time in 1 Post
Send a message via ICQ to rini90 Send a message via MSN to rini90 Send a message via Skype™ to rini90
Question perl binary to decimal and hex

Hi everybody,

i have a problem, i have to write a perl script to translate binar numbers to decimal and hex and the same back.

All I know is, that i have to use Operators like OR, XOR, AND, NOR... also mod, switch
It isn't allowed to use pack and sprintf.

Well the problem is, that i have no programming skills.

I know that e.g. Hex 1A2 is in Decimal 418 because i have to calulate like that
2x1 = 2
+ 10x16= 160
+ 1x256= 256
-----------------------
418

Decimal in binar e.g. Dec 40 = 101000 because

40/2 =20 left 0
20/2 =10 left 0
10/2= 5 left 0
5/2 =2 left 1
2/2 =1 left 0
1/2 =0 left 1
------------------------------
101000

and i also know that bin. in dec is e.g.bin 1010 is dec10 because

1x1² =1
+ 0x2²= 0
+ 1x3²= 9
+ 0x4² =0
------------------
10

So but know i don't know how to write an Perl script with all these infos .

Please help

Thx

rini
__________________
You've tried your best, but the best isn't good enough

Last edited by rini90; 15th April 2009 at 15:52.
Reply With Quote
Sponsored Links
  #2  
Old 17th April 2009, 11:40
vernond vernond is offline
Junior Member
 
Join Date: Apr 2009
Location: Johannesburg
Posts: 4
Thanks: 0
Thanked 0 Times in 0 Posts
Send a message via Skype™ to vernond
 
Default

Check out the link below for a quick 'n easy demo of what you're wanting to do.


http://www.jb.man.ac.uk/~slowe/perl/binary.html
Reply With Quote
Reply

Bookmarks

Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump


All times are GMT +2. The time now is 06:23.


Powered by vBulletin® Version 3.8.7
Copyright ©2000 - 2013, vBulletin Solutions, Inc.