- Community Home
- >
- Servers and Operating Systems
- >
- Operating Systems
- >
- Operating System - HP-UX
- >
- Re: Hexadecimal conversion
Categories
Company
Local Language
Forums
Discussions
Forums
- Data Protection and Retention
- Entry Storage Systems
- Legacy
- Midrange and Enterprise Storage
- Storage Networking
- HPE Nimble Storage
Discussions
Discussions
Discussions
Discussions
Forums
Forums
Discussions
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
- BladeSystem Infrastructure and Application Solutions
- Appliance Servers
- Alpha Servers
- BackOffice Products
- Internet Products
- HPE 9000 and HPE e3000 Servers
- Networking
- Netservers
- Secure OS Software for Linux
- Server Management (Insight Manager 7)
- Windows Server 2003
- Operating System - Tru64 Unix
- ProLiant Deployment and Provisioning
- Linux-Based Community / Regional
- Microsoft System Center Integration
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Community
Resources
Forums
Blogs
- Subscribe to RSS Feed
- Mark Topic as New
- Mark Topic as Read
- Float this Topic for Current User
- Bookmark
- Subscribe
- Printer Friendly Page
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО05-24-2001 05:10 PM
тАО05-24-2001 05:10 PM
I am trying to write a shell script. Is there a command ( utility ) that I can put that will take a number ( base ten ) and convery it to a hexadecimal number and also the other way around?
Also, is there a way to read a certain directory and copy certain files into another directory?
Thank you for your help,
Sanjay
Solved! Go to Solution.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО05-24-2001 06:05 PM
тАО05-24-2001 06:05 PM
Re: Hexadecimal conversion
I have a c program I wrote to convert number between octal, hex and decimal. Maybe you'll find it handy. Save it to convert.c than do "cc convert.c -o convert. Than you can run it by just typing convert. I've included an example. Hope this helps.
main()
{
/* Declare variables */
int number ;
char ibase ;
printf ("Enter base of input number (h)ex, (d)ec, (o)ctal - ") ;
scanf ("%c", &ibase) ;
switch ( ibase )
{
case 'h' :
printf ("Enter the HEX number - ");
scanf ("%x", &number ) ;
printf ("Decimal = %d\nOctal = %o\n", number, number );
break ;
case 'd' :
printf ("Enter the DECIMAL number - ");
scanf ("%d", &number ) ;
printf ("Hex = %x\nOctal = %o\n", number, number );
break ;
case 'o' :
printf ("Enter the OCTAL number - ");
scanf ("%o", &number ) ;
printf ("Decimal = %d\nHex = %x\n", number, number );
break ;
}
}
Run "convert"
$ convert
Enter base of input number (h)ex, (d)ec, (o)ctal - h
Enter the HEX number - 20
Decimal = 32
Octal = 40
As for your second question there are many way to copy files from one directory to another
You can use find
Peggy
- Tags:
- cpio
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО05-24-2001 06:36 PM
тАО05-24-2001 06:36 PM
Re: Hexadecimal conversion
Since you mentioned 'certain' files in 'certain' directories, a standard cp command, perhaps with -p option to retain the original timestamps and permissions. cd to the source directory and use regular expressions to define 'certain' files.
Bill Hassell, sysadmin
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО05-24-2001 06:41 PM
тАО05-24-2001 06:41 PM
SolutionPeggy has given you a c method but there is a way to do it from the shell using the 'bc' binary calculator command. Try This:
#! /usr/bin/sh
# ------------------ Hex to Decimal Converter
while [ $# -ge 1 ]
do
INPUT=$1
shift
echo "obase=10;ibase=16;${INPUT};quit" | bc
done
#! /usr/bin/sh
# ------------------ Decimal to Hex Converter
while [ $# -ge 1 ]
do
INPUT=$1
shift
echo "obase=16;ibase=10;${INPUT};quit" | bc
done
Each of these takes any number of input arguments and converts them to the other radix one per line.
Regards, Clay
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО05-25-2001 06:05 AM
тАО05-25-2001 06:05 AM
Re: Hexadecimal conversion
Another way:
# printf "%#d\n" 0xf
# printf "%#x\n" 15
...JRF...
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО07-26-2012 10:53 PM
тАО07-26-2012 10:53 PM
Re: Hexadecimal conversion
Hi,
Is there any Tandem SQL or TAL procedures or Cobol snippets to convert a decimal Number to Hexadecimal String.. There are easy steps available in C however we would like to have it in Tandem SQL or TAL or COBOL... Thanks ins advance..
Regards,
Manikanda
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО07-27-2012 08:26 AM
тАО07-27-2012 08:26 AM
Re: Hexadecimal conversion
You can also use the shell builtin typeset to convert:
typeset -i16 x=256; echo "$x (256 in hex)"
typeset -i10 y=16#100; echo "$y (0x100 in decimal)"