How to sum space delimited hex values in a string, and do other stuff?

Hello
I am trying to write a Bourne shell script that takes a non-constant-length character string as input, converts each character to hexidecimal value, sums each value, takes the two's complement of the sum, logically ANDS it with FF, and if any of the resultant "nibbles" are a-f, print/save that nibble as A-F, for later display as a two-character-long character string
For example, assume a variable (as in non-constant) length variable $A
A="w04:0;2"
the road that I started down was to define
B=$( echo $A | od -An -t x1 -N"${#A}" )
# for this example, $B=77 30 34 3a 30 3b 32
It's the middle part where I need some magic. What I want to do is add the whitespace-delimited hex values of this string, for this example
C=77+30+34+3a+30+3b+32
so for this example, $C=1b2
then take two's complement of $C; for this example, $TWOS_COMP=ffff ffff ffff ffe4e
and logically AND it with FF; for this example, almost-final answer is 4e
then save final result as uppercase character string variable (for this example, variable's contents would be 4E)
Is what I'm trying to do intuitively obvious to any of you gurus out there, that could rattle off an answer? I'm okay with trashing my approach thus far and trying something totally different, within the constraint that it run inside a Bourne shell script.
Thanx in advance, if anybody can help!

I've made progress. I've converted each character of a non-constant-length string $A into a space-delimited string of hex values, added them up, and retained the least significant byte (i.e., the 8 least significant bits). Here's how:
B=$( echo $A | od -An -t x1 -N"${#A}" )
D=0
for C in $B; do
  C=0x$C
  D=$(($D + $C))
done
D=$(($D & 16#FF))
D=`echo "ibase=10;obase=16;$D" | bc`
The missing piece now is how to take the two's complement of $D. Anybody out there with any ideas on how to handle the two's complement piece inside a Bourne shell?
Thanx

Similar Messages

  • How to get space between two values in a single cell of a table.

    hello,
            how to get space between two values in a single cell of a table.
    thanks a lot.
    kailash.

    sorry i got the answer.

  • How do I get a time value in days, hours and minutes returned to a cell from a calculation of distance divided by speed?

    How do I get a time value in days, hours and minutes returned to a cell from a calculation of distance divided by speed?

    Simon,
    you can use the duration function:
    B4=DURATION(0,0,B1/B2)
    you can further, format the cell as a duration like this using the cell inspector:

  • I need to deactivate two old computers and reinstall CS3 on two new computers. How can I do this if one is long gone and the other just crashed?

    I need to deactivate two old computers and reinstall CS3 on two new computers. How can I do this if one is long gone and the other just crashed?

    contact adobe support and request an activation count reset, http://helpx.adobe.com/x-productkb/global/service1.html

  • How can I change a hex value to normal without changing the characters

    How can I change "3932" (hex displayed string) to "39 32" (normal displayed string with space)
    Solved!
    Go to Solution.
    Attachments:
    Hex to Normal without changing value.vi ‏5 KB

    I think your VI works and if I understand what your input data looks like and the output that you want is, does it?I really can't see a better way. Does it not work for what you want? What form is the actual data in as you receive it? (not how it is displayed by the display setting of the string control) You have the string control set the “Hex display” and that may be confusing some of us as to what the actual input data is.
    And what you want your output to look like. Do you get a “stream” of bytes that are the actual numbers in the form of a string?or Do you get a “string” of ASCII char that represent numbers?
    These are two different things, but may look alike depending on the display setting of your controls are set.
     Changing the display mode of a control or indicator does not change the under lying data. It only changes the way your eye “see” it, not how LabVIEW “sees” it.  We need to know what your raw input string looks like.
    tbob's snipit assume your data is one way and your VI assumes another.
    Omar
    Omar

  • How do I read a hex value and then convert to the binary equivalent?

    I am reading hex values from a register on my unit under test. I only want to monitor certain bits in the hex value to check a status. I have everything down to run the program except how to read my hex values in binary form. Any suggestions out there?

    If this is just a matter of display, then right click and choose "Format & Precision...". Beware, this works only with integer indicators (I8/16/32 and U8/16/32).
    If the problem is to extract a bit value in a specific position, then go to the "Advanced >> Data manipulation" sub-palette where are all bit manipulation functions (rotate, shift, split...).
    Don't forget either the logical functions (And, Or...) in the boolean sub-palette, where is also the "number to boolean array" function (to be used in conjunction with an index array node).
    Another option is to use string conversion functions, in the "String >> String/Number conversion" sub palette.
    Have a look to the attached image.
    Enough ?
    Chilly Charly    (aka CC)
             E-List Master - Kudos glutton - Press the yellow button on the left...        
    Attachments:
    Hex_&Bin.tif ‏20 KB

  • Assigning a hex value to a variable and getting binary value of a variable.

    I try to develop java programs and I need to do a conversion unicode to EBCDIC and vice versa.
    How can I assign hex values to variables to build UTF-EBCDIC and EBCDIC-UTF table and get hex or binary value of data to compare it to value of in the table?
    I did a conversion like this with PL/1 before. I do not know how can I do it with Java. Because I am new to Java.
    Thank you in advance.

    I will run java code in mainframe and java uses
    unicode for data in default and mainframe environment
    is EBCDIC. So I have to translate the data from
    unicode to ebcdic.I said I think String supports EBCDIC encoding...
    String ebcdic = new String(ebcdicBytes, "Cp500");
    http://java.sun.com/j2se/1.4.2/docs/guide/intl/encoding.doc.html

  • I Forgotten My Restriction Code!! How Can I Get It Back????And My "other" Tab In iTunes Is REALLY Large!!! Reply ASAP

    So I Put A Restriction Code 3 Months Back And Now I Forgot It What Should I Do??? Plz Help!!! And My "Other" Tab On My iPod Is Large And It Took 2.5 Gb How Can I Remove This???

    For the Restrictions passcode, you need to restore the iPod to factory defaults/new iPOd.  That will also eliminate the large "other".

  • How to sum row level multiplication values between two measure?

    Hi All ,
    In the CUBE i want to create a calculation , which in SQL Server is = sum(calldur*callind). The calldur is a measure which has numeric values. Callind has values of 1 and 0 (factless fact ). please see the below datasets.
    calldur callind sum(caldur*callind)
    54 1 54
    0 0 0
    25 1 25
    58 0 0
    31 1 31
    300 0 0
    297 0 0
    but what the cube is doing is (call dur is selected as sum measure) and i selected (callind as max value)
    adding all the calldur which is 765*1, where as the value should be sum of sum(calldur*callind) which is 110.please need help.
    Thanks
    SV

    The simplest way to do this is to do the multiplication in the query that you are using as the source for your measure group or to add a calculated column in your DSV.
    Another solution would be to use a measure expression in the cube, but this has much worse performance as it effectively forces the storage engine to alway scan at the lowest level.
    http://darren.gosbell.com - please mark correct answers

  • How to Capture the user command value instead of ucomm and pfkey from syst

    Hi,
    How to capture the value of enter key in the enhancements.
    Iam getting the sy-ucomm value as space. Please let me know the better solution ASAP.
    regards
    Nagendra

    Hello,
    If is a module pool program, take a look to the variable defined to receive the user-command (you can see this in the screen painter).
    Regards.

  • How can I get all the values of a String array profile property using javascript?

    I am trying to build functionality into our site that records all products added to the basket against a user's profile.
    I have so far been able to store the product codes against the profile as a property using Ajax:
           var dataString = ":formid=addProduct&:formstart=/apps/thread/templates/page_product/jcr:content/par/produc t/formstart&:redirect=/content/thread/en/user/cart.html&productId=151515:profile="+profile ;
                         $.ajax({ 
                type: "POST", 
                url: "/content/women/evening/dresses/l-k-bennett-davinadress.html", 
                data: dataString, 
                success: function(data) { 
    In this example I have hardcoded a product ID of 151515.
    In order to save the property as a multi string field you simply replace &productId=151515 with &productId=151515&productId=131313&productId=141414 or as many extra values as you want to build into that string. This stores a productId property against a user profile.
    The issue comes from calling that data back. Using var value = CQ_Analytics.ProfileDataMgr.getProperty("productId") I can get the first value of this array (or the single value if only one is stored).
    However there does not seem to be a way to get any of the other stored values in the array using getProperty. Does anyone know how I can achieve this?

    Hi,
    Don't think that's possible. Even if it were, you wouldn't be able to use/display BOOLEAN type in SQL.
    If you just aim to see what they are, you could do something like this
    select text
      from all_source
    where owner = 'SYS'
       and name = 'DBMS_DB_VERSION'
       and type = 'PACKAGE';Or even
    select dbms_metadata.get_ddl('PACKAGE', 'DBMS_DB_VERSION', 'SYS') from dual;My version is:
    SQL> select * from v$version where rownum = 1;
    BANNER                                                         
    Oracle Database 10g Enterprise Edition Release 10.2.0.4.0 - 64bi
    1 row selectedIn 11g you also have [PL/SCOPE|http://download.oracle.com/docs/cd/E11882_01/appdev.112/e10471/adfns_plscope.htm#ADFNS02203] which might help you even more.
    Regards
    Peter

  • How can I select the time values of a signal and connect them to the y-input of a divide command?

    Hi,
    I have an analog signal connected with a threshold peak detector. The counted peaks shall be divided by the total time of the recorded signal. My problem is, I don't know how to connect just the the x-values, i.e. the time component of the signal, to the divide command. I have no idea how to "split" the signal so that I don't have the whole signal but just the time in seconds as an output of the measured or filtered signal sub-VI, respectively.
    Does anyone have a hint?
    Thanks for your help,
    Philipp

    Hi Phillipp,
    do you mean you have a waveform and you want to get the components? In this case "Get Waveform Components" should work.
    Mike

  • How can I read an ID-value from the LMS and insert this into an URL?

    Hi
    Right now I am struggling with a little problem. Hopefully anyone here knows the answer. For the latest course I am building (Captivate 6), it is necessary that at one point the course reads an ID-value from the LMS. After that, this ID should be inserted into an URL.
    To be more precisely: the ID must be read (getValue) from cmi.archive_id and inserted into an URL like that: http://.../archive.php?action=pdf&objectID=ARCHIVE_ID.
    Unfortunately I am more of a designer und less of a javascript-maestro (well...I am a javascript-noob to be precisely), therefore I am pretty clueless how to do that. I tried a simple executed action (run Javascript: cpEIGetValue('cmi.archive_id'); and after that open URL http://.../archive.php?action=pdf&objectID=ARCHIVE_ID), but...well...that didn't work.
    Any ideas?
    Thanks a lot in advance

    Think you'll find help looking at Jim Leichliter's website:
    http://captivatedev.com/
    He has great tutorials about JavaScript and also a widget that allows to enter a variable in URL's
    Lilybiri

  • How to delete spaces between each characters of a string in a file

    In my program, I have a string, for example: str='abcdefg', when I print the string in command window, there is no space, everything is Ok But when I use the following method to write the string in a file(Mystring.txt):
    File file= new File("C:\\MyString.txt");
    fos = new FileOutputStream(file);
    dos=new DataOutputStream(fos);
    dos.writeChars(str);
    when I open the file, between each character , there is a space, like "a b c d e f g", how to solve this problem? any idea or method?

    The spaces appear because you are using a DataOutputStream.
    In fact, a DataOutputStream uses a specific way to encode primitive types. Moreover, data written through a DataOutputStream are supposed to be read back using a DataInputStream.
    You should better use a FileWriter (or an OutputStreamWriter) instead.

  • How much HDD space should Leopard consume on an "erase and install" install

    I installed Leopard into my 17 In MacBook Pro and the 92 Gig HDD is now half full and I only have about 14 gig of music on the HDD.
    I would figure the OS take about 14 to 18 gig max, so my question is, did the installed keep the old stuff and if so how do I reclaim the HDD space back.
    Hope someone and point me in te right direction
    Thanks
    Newport Tom

    If you did an Erase and Install then nothing should be on the drive except what you installed. You might try this:
    Repairing the Hard Drive and Permissions
    Boot from your OS X Installer disc. After the installer loads select your language and click on the Continue button. When the menu bar appears select Disk Utility from the Installer menu (Utilities menu for Tiger and Leopard.) After DU loads select your hard drive entry (mfgr.'s ID and drive size) from the the left side list. In the DU status area you will see an entry for the S.M.A.R.T. status of the hard drive. If it does not say "Verified" then the hard drive is failing or failed. (SMART status is not reported on external Firewire or USB drives.) If the drive is "Verified" then select your OS X volume from the list on the left (sub-entry below the drive entry,) click on the First Aid tab, then click on the Repair Disk button. If DU reports any errors that have been fixed, then re-run Repair Disk until no errors are reported. If no errors are reported click on the Repair Permissions button. Wait until the operation completes, then quit DU and return to the installer. Now shutdown the computer for a couple of minutes and then restart normally.
    If DU reports errors it cannot fix, then you will need Disk Warrior (4.0 for Tiger, and 4.1 for Leopard) and/or TechTool Pro (4.6.1 for Leopard) to repair the drive. If you don't have either of them or if neither of them can fix the drive, then you will need to reformat the drive and reinstall OS X.

Maybe you are looking for

  • Which HD to upgrade with?

    So, a friend just gave me two 2,5" drives. Both samsung. a 320gb 5400rpm and a 500gb in a case. Can't tell what rpm. My current set up is MBP 2.16ghz 3gb ram 250gb wd hdd. The HD was originally a 120gb. Now, I'm thinking of sticking the 320gb in the

  • Customer Care & Billing platforms (AS400)

    I've been searching for information about what platforms does CC&B run. I've not been vey lucky so far. So my quesiton is does CC&B run on an AS400? Thanks

  • Which tables are used...

    Hello I have a script, which makes a lot of things on the database. Is there a tool or a script, that I can see which tables are used by the script? Thanks for the help. roger

  • Shared Pool utilisation

    Hello Team: I ran a metalink script to report the shared pool utilization recently. I took this output when the database was on peak load. SQL> / Obj mem: 66435759 bytes (63.36MB) Shared sql: 324219036 bytes (309.2MB) Cursors: 341207073 bytes (325.4M

  • Configurator in cs5

    I may be jumping the gun here, but at a cursory glance »What's new in Photoshop CS5« (http://www.adobe.com/products/photoshop/photoshop/whatsnew/index.html?segment=photography& promoid=FDTEW) does not seem to make any mention of Configurator – so do