LinuxQuestions.org
Share your knowledge at the LQ Wiki.
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Software > Linux - Kernel
User Name
Password
Linux - Kernel This forum is for all discussion relating to the Linux kernel.

Notices

Reply
 
LinkBack Search this Thread
Old 11-18-2008, 12:58 AM   #1
ayaskant16
LQ Newbie
 
Registered: Apr 2008
Posts: 6

Rep: Reputation: 0
shell command to add two non integer hexadecimal value


hi,
do anyone know any command to how to add for example

0x10e0 and 0x0008 .

for adding integers i know it is "expr" but for the above kind of addition i am not able to get the command

thanks in advance
 
Old 11-18-2008, 07:32 AM   #2
JZL240I-U
Senior Member
 
Registered: Apr 2003
Location: Germany
Distribution: SuSE 11.4_64-KDE, 12.1_64-KDE
Posts: 3,281

Rep: Reputation: Disabled
From http://www.tldp.org/LDP/Bash-Beginne...e.html#chap_03
Chapter 3.4.6:

...
Shell variables are allowed as operands; parameter expansion is performed before the expression is evaluated. Within an expression, shell variables may also be referenced by name without using the parameter expansion syntax. The value of a variable is evaluated as an arithmetic expression when it is referenced. A shell variable need not have its integer attribute turned on to be used in an expression.

Constants with a leading 0 (zero) are interpreted as octal numbers. A leading "0x" or "0X" denotes hexadecimal. Otherwise, numbers take the form "[BASE'#']N", where "BASE" is a decimal number between 2 and 64 representing the arithmetic base, and N is a number in that base. If "BASE'#'" is omitted, then base 10 is used. The digits greater than 9 are represented by the lowercase letters, the uppercase letters, "@", and "_", in that order. If "BASE" is less than or equal to 36, lowercase and uppercase letters may be used interchangably to represent numbers between 10 and 35.

Operators are evaluated in order of precedence. Sub-expressions in parentheses are evaluated first and may override the precedence rules above.

Wherever possible, Bash users should try to use the syntax with angular brackets:

$[ EXPRESSION ]

However, this will only calculate the result of EXPRESSION, and do no tests:

franky ~> echo $[365*24]
8760


...

Last edited by JZL240I-U; 11-18-2008 at 09:32 AM.
 
Old 11-18-2008, 08:22 AM   #3
pixellany
Guru
 
Registered: Nov 2005
Location: Pasadena, CA
Distribution: Arch+KDE
Posts: 16,552

Rep: Reputation: 412Reputation: 412Reputation: 412Reputation: 412Reputation: 412
Quote:
Originally Posted by ayaskant16 View Post
hi,
do anyone know any command to how to add for example

0x10e0 and 0x0008 .

for adding integers i know it is "expr" but for the above kind of addition i am not able to get the command

thanks in advance
Those ARE integers!! In basic BASH, you cannot do non-integer math.

This works:
printf "%x\n" $((0x10e0+0x0008))
 
Old 11-19-2008, 04:59 AM   #4
ayaskant16
LQ Newbie
 
Registered: Apr 2008
Posts: 6

Original Poster
Rep: Reputation: 0
thanks a lot. i am now converting the no to decimal and then adding with the decimal value.
 
  


Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search

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 Off
HTML code is Off
Trackbacks are Off
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Bash + How to add Hexadecimal numbers trscookie Programming 7 09-03-2007 05:22 PM
how to add user in command shell man_J Linux - Software 4 11-05-2006 09:09 AM
Test variable is an integer in shell judgex Programming 1 06-03-2006 10:12 PM
function in shell to convert hexadecimal into ascii suchi_s Linux - Software 1 04-01-2005 03:07 PM
converting integer value to hexadecimal string in C - any suggestions?? woodywellhung Programming 3 04-24-2004 06:27 PM


All times are GMT -5. The time now is 05:16 PM.

Main Menu
 
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
identi.ca: @linuxquestions
Facebook: @linuxquestions
Open Source Consulting | Domain Registration