Sponsored Content
Homework and Emergencies Homework & Coursework Questions Splitting a numbers binary representation for a double. Post 302665447 by robin_simple on Monday 2nd of July 2012 09:38:27 PM
Old 07-02-2012
Code:
#include <iostream>
#include <stdlib.h>
using namespace std;

int main()
{
        char *hex_key = "abcdef012345678";
        long long key = strtoll( hex_key, NULL, 16 );

        cout << key << endl;
}

on compilation:
g++ b.cpp
b.cpp: In function ‘int main()’:
b.cpp:7: warning: deprecated conversion from string constant to ‘char*’

output:
./a.out
773738358679819896

Is there anything I can do to get rid of the warning?

Also, the full hex_key is 9abcdef012345678 which is different from what I used in the above code because of the 9 at the beginning. The output of this is 9223372036854775807
which is different from a result shown on a webpage that calculates hexadecimal numbers. All the outputs for the other hex_key values are consistent with the calculating website. Why is this number different?

Also, in your first reply you gave me
Code:
unsigned char *cval = "123";
    int val = 0;
    int i;

    for( i = 0; i < strlen( cval ); i++ )
    {
        val <<= 4;
        val += cval[i] - '0';
    }
    printf( "%x\n", val );

and I am wondering why you subtract '0' and why you shift 4. Is it necessary to shift << by four each time you add a new hex digit?

---------- Post updated at 08:38 PM ---------- Previous update was at 12:56 PM ----------

ok, strtoull() was the function that gets the whole 16 hex digits. the unsigned long long type was what I should have been using.
 

8 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Using binary representation of IEEE 754

Hi! What is the way to get the binary representation of a IEEE 754 (like 0001110110001111010101100111001011100100101010111101) without using perl. Bash for example, would be fine. I need to put that representation in a string for some operation and then to put that string back in a float. ... (3 Replies)
Discussion started by: Zephyr
3 Replies

2. Programming

Internal representation of double

I came across a puzzle which I can not explain. The setup is SCO OpenServer 5.7 (32 bit OS) and native SCO compiler. double is 8 bytes long on this system. I am able to populate the double variable with two different sets of values that produces the same double value, please see below: #include... (7 Replies)
Discussion started by: migurus
7 Replies

3. Shell Programming and Scripting

Splitting file based on line numbers

Hello friends, Is there any way to split file from n to n+6 into 1 file and (n+7) to (n+16) into other file etc. f.e I have source pipe delimated file with 20 lines and i need to split 1-6 in file1 and 7-16 in file2 and 17-20 in file 3 I need to split into fixed number of file like 4 files... (2 Replies)
Discussion started by: Rizzu155
2 Replies

4. Shell Programming and Scripting

Put double quotes around numbers

Hi, consider a file which has data such as "random text",912345,"54","finish" "random text",9991236745,"9954","finish" I want to replace the numbers that don't have double quotes around them with ones that do; so the output should be "random text","912345","54","finish" "random... (4 Replies)
Discussion started by: Storms
4 Replies

5. Shell Programming and Scripting

Splitting a file based on positive and negative numbers

Dear All, I have to split a tab delimited file in two files based on the presence of a positive or negative in column number 9 , for example file: A 1 5 erg + 6766 0.9889 0.9817 9.01882 erg inside upstream B 1 8 erg2 + 6766 0.9889 0.9817 -9.22 erg2 inside... (3 Replies)
Discussion started by: paolo.kunder
3 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. Programming

How bit representation of a number can be done in c?

I have an assignment in which a character is the input of which some bits(from a position to certain position) are to be inverted (1's complement) and then the resultant character is to be returned....for example unsigned char x = J from p = 3 to offset n = 5 01001010 inverted to... (1 Reply)
Discussion started by: ezee
1 Replies

8. UNIX for Beginners Questions & Answers

Splitting a file based on negative and positive numbers

I have a file that is pipe delimited and in Column F they have number values, both positive and negative. I need to take the one file I am starting with and split it into two separate files based on negative and positive numbers. What is the command to do so? And then I need to also transfer... (4 Replies)
Discussion started by: cckaiser15
4 Replies
lmfsetup(8)						      System Manager's Manual						       lmfsetup(8)

Name
       lmfsetup - License Management Facility PAK registration script

Syntax
       /etc/lmfsetup [ template ]

Description
       The  script allows you to register data supplied by a Product Authorization Key (PAK).  The script prompts you for the data associated with
       each of the fields on a PAK.  When all the data has been entered, the License Management Facility (LMF) ensures there are  entries  against
       all  the mandatory fields, and that the Checksum validates all the license data.  If the data has been entered correctly, the PAK is regis-
       tered in the License Database.  If the data has been entered incorrectly, the appropriate error message is displayed and you are given  the
       opportunity to re-enter the data.

       The template option allows you to register license data from templates in A template containing a partially complete PAK is created by some
       products as part of their installation process.	The script only prompts you for data on the fields that are empty in the template.  If the
       script cannot find the specified template in it searches the current directory.

       The  script  is	provided as an alternative to the command.  This displays a template, which includes the fields on the PAK, and invokes an
       editor so that you can add the license data to the appropriate field.  The command also allows errors to be corrected without having to re-
       enter all the data.

See Also
       lmf(8)
       Guide to Software Licensing

																       lmfsetup(8)
All times are GMT -4. The time now is 02:17 PM.
Unix & Linux Forums Content Copyright 1993-2022. All Rights Reserved.
Privacy Policy