Sponsored Content
Top Forums Shell Programming and Scripting Decimal to Hexadecimal conversion Post 302089465 by blowtorch on Tuesday 19th of September 2006 06:53:17 AM
Old 09-19-2006
You might be using sh. In that case, replace
Code:
$(echo "ibase=10;obase=16;$i" | bc)

with
Code:
`echo "ibase=10;obase=16;$i" | bc`

It should work. I checked.
 

10 More Discussions You Might Find Interesting

1. UNIX for Dummies Questions & Answers

Convert hexadecimal to decimal base

Hello ! Does anyone knows how can I convert hexadecimal to decimal base in the ksh or csh script ?? Thanks ! Witt (1 Reply)
Discussion started by: witt
1 Replies

2. UNIX for Dummies Questions & Answers

Hexadecimal to Decimal

Hi all, I have a small script to convert my HexaDecimal Input to Decimal as output. #!/bin/ksh hd=00208060 dec=`printf %d $hd` echo $dec Output of the above program: printf: 00208060 not completely converted 16 But my expected output is "2130016". How can i acheive this. I... (2 Replies)
Discussion started by: Arunprasad
2 Replies

3. Shell Programming and Scripting

need help with ascii to decimal conversion

Hi, Can anyone please help me ascci to decimal conversion in bash I have a file which contains stream of numbers like this,these are ascci values 729711810132973278105991013268971213233 I want to covert it to its actual value like upper code's decimal is "Have a Nice Day!" ... (15 Replies)
Discussion started by: sunilmenhdiratt
15 Replies

4. Shell Programming and Scripting

Decimal to hex conversion

Dear All PROs Thanks in advance need a shell for Decimal to hex conversion input file (decimal values) 65,5,48,66,133,131,118,47 65,5,48,66,133,131,83,63 . . desire output should be (Hex value)... (11 Replies)
Discussion started by: The_Archer
11 Replies

5. Shell Programming and Scripting

To convert file with decimal to another file with Hexadecimal

I have a text file of alphanumeric values listed one by one. I have to convert them to hexadecimal equivalents for each character seperated by ":" in Unix bash shell script. For example, 12345678 has to be converted to 31:32:33:34:35:36:37:38 (10 Replies)
Discussion started by: mathie
10 Replies

6. Shell Programming and Scripting

NAWK conversion of hexadecimal input to decimal output via printf, I am close I can feel it

I have searched and the answers I have found thus far have led me to this point, so I feel I am just about there. I am trying to convert a column of hexadecimal to decimal values so that I can filter out via grep just the data I want. I was able to pull my original 3 character hex value and... (10 Replies)
Discussion started by: PCGameGuy
10 Replies

7. Shell Programming and Scripting

Convert hexadecimal value in decimal value

hi all, this is my script: #! /bin/sh minutes=$( { i2cget -f -y 0 0x51 3; } 2>&1 ) minutes=${minutes:2} hour=$( { i2cget -f -y 0 0x51 4; } 2>&1 ) hour=${hour:2} day=$( { i2cget -f -y 0 0x51 5; } 2>&1 ) day=${day:2} month=$( { i2cget -f -y 0 0x51 7; } 2>&1 ) month=${month:2} ... (6 Replies)
Discussion started by: enaud
6 Replies

8. Shell Programming and Scripting

Hexadecimal to Binary conversion

Hi Guys, Is it possible to convert the hexadecimal to Binary by unix command.....I could not figure out.... If I need to convert AF6D to binary...what could be the way to do? Thanks in advance!! ---------- Post updated at 02:57 AM ---------- Previous update was at 02:42 AM ---------- I... (6 Replies)
Discussion started by: Indra2011
6 Replies

9. Shell Programming and Scripting

Conversion from Hexadecimal to binary

How can I convert hexadecimal values to Binary from the second field to the end Input: WS-2 23 345 235 DT-3 45 4A3 000 pp-2 76 300 E4 Output: WS-2 100011 1101000101 1000110101 DT-3 1000101 10010100011 000 pp-2 1110110 1100000000 11100100 (16 Replies)
Discussion started by: aydj
16 Replies

10. UNIX for Dummies Questions & Answers

Convert hexadecimal value to decimal value

Hi All, cat filename | awk '{print $1, $2, $4, $5, $6, $7, $8, $9, $10;}' | awk 'NF > 0' OUTPUT: 2015-01-19 00:12:32 00000000fbfa0000 000000009ae5cf80 014d 015d 0017 003c 0362de20 2015-01-19 00:13:52 00000000fc820000 00000000994c6758 014c 015d 000b 003c 08670250 2015-01-19 00:14:25... (12 Replies)
Discussion started by: sam@sam
12 Replies
bc(1)								   User Commands							     bc(1)

NAME
bc - arbitrary precision arithmetic language SYNOPSIS
/usr/bin/bc [-c] [-l] [file...] /usr/xpg6/bin/bc [-c] [-l] [file...] DESCRIPTION
The bc utility implements an arbitrary precision calculator. It takes input from any files given, then reads from the standard input. If the standard input and standard output to bc are attached to a terminal, the invocation of bc is interactive, causing behavioral con- straints described in the following sections. bc processes a language that resembles C and is a preprocessor for the desk calculator pro- gram dc, which it invokes automatically unless the -c option is specified. In this case the dc input is sent to the standard output instead. USAGE
The syntax for bc programs is as follows: L Means a letter a-z, E Means an expression: a (mathematical or logical) value, an operand that takes a value, or a combination of operands and operators that evaluates to a value, S Means a statement. Comments Enclosed in /* and */. Names (Operands) Simple variables: L. Array elements: L [ E ] (up to BC_DIM_MAX dimensions). The words ibase, obase (limited to BC_BASE_MAX), and scale (limited to BC_SCALE_MAX). Other Operands Arbitrarily long numbers with optional sign and decimal point. Strings of fewer than BC_STRING_MAX characters, between double quotes ("). ( E ) sqrt ( E ) Square root length ( E ) Number of significant decimal digits. scale ( E ) Number of digits right of decimal point. L ( E , ... , E ) Operators + - * / % ^ (% is remainder; ^ is power) ++ -- (prefix and postfix; apply to names) == <= >= != < > = =+ =- =* =/ =% =^ Statements E { S ;... ; S } if ( E ) S while ( E ) S for ( E ; E ; E ) S null statement break quit .string Function Definitions define L ( L ,..., L ) { auto L ,..., L S ;... S return ( E ) } Functions in -l Math Library s(x) sine c(x) cosine e(x) exponential l(x) log a(x) arctangent j(n,x) Bessel function All function arguments are passed by value. The value of a statement that is an expression is printed unless the main operator is an assignment. Either semicolons or new-lines may separate statements. Assignment to scale influences the number of digits to be retained on arithmetic operations in the manner of dc. Assignments to ibase or obase set the input and output number radix respectively. The same letter may be used as an array, a function, and a simple variable simultaneously. All variables are global to the program. auto variables are stacked during function calls. When using arrays as function arguments or defining them as automatic variables, empty square brackets must follow the array name. OPTIONS
The following operands are supported: -c Compiles only. The output is dc commands that are sent to the standard output. /usr/bin/bc -l Defines the math functions and initializes scale to 20, instead of the default zero. /usr/xpg6/bin/bc -l Defines the math functions and initializes scale to 20, instead of the default zero. All math results have the scale of 20. OPERANDS
The following operands are supported: file A pathname of a text file containing bc program statements. After all cases of file have been read, bc reads the standard input. EXAMPLES
Example 1: Setting the precision of a variable In the shell, the following assigns an approximation of the first ten digits of n to the variable x: x=$(printf "%s " 'scale = 10; 104348/33215' | bc) Example 2: Defining a computing function Defines a function to compute an approximate value of the exponential function: scale = 20 define e(x){ auto a, b, c, i, s a = 1 b = 1 s = 1 for(i=1; 1==1; i++){ a = a*x b = b*i c = a/b if(c == 0) return(s) s = s+c } } Example 3: Printing the approximate values of the function Prints approximate values of the exponential function of the first ten integers: for(i=1; i<=10; i++) e(i) or for (i = 1; i <= 10; ++i) { e(i) } ENVIRONMENT VARIABLES
See environ(5) for descriptions of the following environment variables that affect the execution of bc: LANG, LC_ALL, LC_CTYPE, LC_MES- SAGES, and NLSPATH. EXIT STATUS
The following exit values are returned: 0 All input files were processed successfully. unspecified An error occurred. FILES
/usr/lib/lib.b mathematical library /usr/include/limits.h to define BC_ parameters ATTRIBUTES
See attributes(5) for descriptions of the following attributes: +-----------------------------+-----------------------------+ | ATTRIBUTE TYPE | ATTRIBUTE VALUE | +-----------------------------+-----------------------------+ |Availability |SUNWesu | +-----------------------------+-----------------------------+ |Interface Stability |Standard | +-----------------------------+-----------------------------+ SEE ALSO
dc(1), awk(1), attributes(5), environ(5), standards(5) NOTES
The bc command does not recognize the logical operators && and ||. The for statement must have all three expressions (E's). SunOS 5.10 29 Aug 2003 bc(1)
All times are GMT -4. The time now is 06:04 AM.
Unix & Linux Forums Content Copyright 1993-2022. All Rights Reserved.
Privacy Policy