Sponsored Content
Top Forums Programming Hexadecimal to binary operation Post 302901517 by chacko193 on Wednesday 14th of May 2014 06:58:23 AM
Old 05-14-2014
file.dat
Code:
0x1A0A0 0x10000 0x1A480 0x3FFFF 0x3FFFF 0x3FFFF 0x3FFFF 0x3FFFF
0x13E01 0x10000 0x12801 0x3FFFF 0x3FFFF 0x3FFFF 0x3FFFF 0x3FFFF
0x10400 0x10000 0x10410 0x3FFFF 0x3FFFF 0x3FFFF 0x3FFFF 0x3FFFF
0x12A03 0x10000 0x12203 0x3FFFF 0x3FFFF 0x3FFFF 0x3FFFF 0x3FFFF

Modified version of your code:
Code:
#include <iostream>
#include <fstream>
#include <sstream>
#include <bitset>
#include <string>
#include <limits>
#include <stdlib.h>
using namespace std;

int main(int argc, char *argv[])
{
  string data16, data32;
  unsigned value;
  bool dodebug = true;

  //open datafile
  std::fstream datafile;
  datafile.open("file.dat",std::fstream::in);

  stringstream ss;
  while(!datafile.eof()) {
  stringstream ssData16, ssData32;
    ss.clear();
    ssData16.clear();
    ssData32.clear();
    datafile >> ws;
    getline(datafile,data16,'\n');
    getline(datafile,data32,'\n');
    ssData16 << data16;
    ssData32 << data32;
    ssData16 >> data16;
    ssData32 >> data32;
    data16.erase(0,3);
    data32.erase(0,3);
    if(dodebug) cout<<"data :"<< data16<< ", "<<data32<<endl;


    ss << std::hex << data16<< data32;
    ss >> value;
    bitset<32> data(value);
    cout<<"data: "<<data<<endl;
  }
}

Modified version of Corona's code:
Code:
#include <iostream>
#include <fstream>
#include <sstream>
#include <bitset>
#include <string>
#include <limits>
#include <stdlib.h>
using namespace std;

int main(int argc, char *argv[])
{
  string data16, data32;
  unsigned value;
  bool dodebug = true;

  //open datafile
  std::fstream datafile;
  datafile.open("file.dat",std::fstream::in);

  while(!datafile.eof()) {
    datafile >> ws;
    getline(datafile,data16,'\n');
    //if(dodebug) cout<<"data :"<< data16<< ", "<<data32<<endl;

    sscanf(data16.c_str(),"0x1%04x",&value);

    cout<<"data: "<<value<<endl;
  }
}

This User Gave Thanks to chacko193 For This Post:
 

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Get Hexadecimal Value

I have a record in a file that ends with the new line character "\n". How dio I determine the hexadecimal value for that? (2 Replies)
Discussion started by: lesstjm
2 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

Test Hexadecimal number

Hi, I would like test if a number (with 2 digit, for example a9 , 0b ) is a hexadecimal number with 2 digit ? (2 Replies)
Discussion started by: francis_tom
2 Replies

4. Programming

Hexadecimal to ascii

Let's suppose i have a hexadecimal array with 16 cells.for example b3e2d5f636111780 i want to convert it to an array of ascii characters(in C) so that i can reduce total size of the file i want to put it in. But i am afraid i have not fully understand the difference between ascii and hex(i... (3 Replies)
Discussion started by: bashuser2
3 Replies

5. Shell Programming and Scripting

Column operation : cosne and sine operation

I have a txt file with several columns and i want to peform an operation on two columns and output it to a new txt file . file.txt 900.00000 1 1 1 500.00000 500.00000 100000.000 4 4 1.45257346E-07 899.10834 ... (4 Replies)
Discussion started by: shashi792
4 Replies

6. Shell Programming and Scripting

Convert binary file to csv and then back to the binary format

Hello *nix specialists, Im working for a non profit organisation in Germany to transport DSL over WLAN to people in areas without no DSL. We are using Linksys WRT 54 router with DD-WRT firmware There are at the moment over 180 router running but we have to change some settings next time. So my... (7 Replies)
Discussion started by: digidax
7 Replies

7. 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

8. 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

9. UNIX for Advanced & Expert Users

6-digit hexadecimal ID in shell

Hi, i tried to do this script: Generate a "unique" 6-digit hexadecimal identifier for your computer. Do not use the flawed hostid command. Hint: md5sum /etc/passwd, then select the first 6 digits of output. Fom 0 to 9 and from a to f #!/bin/bash clear echo "" echo "--------------------"... (4 Replies)
Discussion started by: jose2802
4 Replies

10. Shell Programming and Scripting

Generate hexadecimal

Hello I'm working on a script to list all ipv6 from given address so I've run this script which create hex part of ipv6 STR2=159 END2=200 SUM2=`expr $END2 - $STR2` for ((i=STR2;i<=END2;++i)); do x=$( printf "%x" $i ) ; echo $x echo -e "::"$x >> netpart.txt done output is : ::9f... (2 Replies)
Discussion started by: nimafire
2 Replies
Xmark(1)						      General Commands Manual							  Xmark(1)

NAME
Xmark - summarize x11perf results SYNTAX
Xmark datafile DESCRIPTION
Xmark is a shell script that reads the indicated datafile and compiles a benchmark which it writes to standard output. It writes three numbers: A weighted performance number for the x11perf results. A weighted performance number for a standard SparcStation 1, with SunOS 4.1.2, X11R5 Xsun, and a CG3 dumb Color Frame Buffer. The Xmark, which is the ratio of the two numbers above. The datafile must be an ordinary file, produced by x11perf in the following way: x11perf -display display -v1.3 -rop GXcopy GXxor -all > datafile It is possible to run the GXcopy and GXxor tests separately, as long as they are concatenated to the same output file: x11perf -display display -v1.3 -rop GXcopy -all > datafile x11perf -display display -v1.3 -rop GXxor -all >> datafile or x11perf -display display -v1.3 -rop GXxor -all > datafile x11perf -display display -v1.3 -rop GXcopy -all >> datafile FILES
temp.$$ Temporary file created in the current directory, deleted after use. DIAGNOSTICS
Usage: Xmark datafile Xmark was invoked without arguments or with more than one argument, or with options. Xmark takes no options. Error: data file does not exist or is not ordinary. Xmark cannot find the datafile named on its command line, or the datafile is a special file such as a directory. WARNING: datafile contains nnn, not 441 or 447 'trep' results; The file named on the command line does not seem to be a file generated by x11perf in the expected way. Diagnostic: ERROR: sum of weights =nnn, not equal to 4566.0; There is an internal error in Xmark. SEE ALSO
X(7), x11perf(1), x11perfcomp(1) X Version 11 x11perf 1.5.4 Xmark(1)
All times are GMT -4. The time now is 03:02 PM.
Unix & Linux Forums Content Copyright 1993-2022. All Rights Reserved.
Privacy Policy