Sponsored Content
Top Forums UNIX for Beginners Questions & Answers How to convert dec to hex in python? Post 303039720 by bigvito19 on Sunday 13th of October 2019 12:24:44 PM
Old 10-13-2019
How to convert dec to hex in python?

When I try to convert big numbers I get extra numbers at the end that doesn't move plus an L character too. How to remove the 4 extra characters at the end 000L?

8b8dbbc584d9c000L

8b8dc4ddd34c6000L

8b8dcdf621bf0000L

8b8dd70e7031a000L

8b8de026bea44000L






Code:
#!/usr/bin/python

    import sys

    def int_tuple_from_cmdline():
      """return exactly two integers form sys.argv
         or die with an error message
      """
      import sys
      args = sys.argv[1:] # drop first entry (progpath)
      if len(args) != 2:
          raise SystemExit("\n#################################################\n# Please enter both a 
    start and stop parameter. #\n#################################################")
      for i in range(len(args)):
          try:
             args[i] = int(args[i])
          except ValueError:
             raise SystemExit("\n#################################################\n# Parameter %d is not an integer. You entered: %s #\n#################################################\n" %(i+1,args[i]))
      return tuple(args)

    start, stop = int_tuple_from_cmdline()

    r = start - 10000000000000
    while r < stop:
	r = r + 50000000000000
	hx = hex(r)[2:]
	print(hx)


Last edited by bigvito19; 10-13-2019 at 01:57 PM..
 

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Convert Char to Dec using AWK

I'm facing a problem when trying to read a file and convert the content from char to decimal in ASCII. :confused: eg :- Input file : 20051231 8.00 experted result : 50484853495051493256464848 The content of input file is vary very day. I need to use AWK script to program it. Pls... (4 Replies)
Discussion started by: jasmine05
4 Replies

2. Programming

to convert int to hex

Hi, Can you help me in converting int value to hex in a single command. Thanks (8 Replies)
Discussion started by: naan
8 Replies

3. Shell Programming and Scripting

converting hex to dec

Hi Experts, I have a file called "hex" which contains info like below How do i convert everything in this file to decimal value? Please advice. Thanks (4 Replies)
Discussion started by: aismann
4 Replies

4. Shell Programming and Scripting

How to Convert Hex value to Dec ?

Hi All, I want to convert below Hex value to Dec value in each column .How to do it ? This data is in a 1 file. 4e20 0475 2710 010f 7530 69a2 7530 7e2f 4e20 02dd 7530 6299 4e20 0c0a 7530 69a2 4e20 0a0b 2710 0048 7530 7955 4e20 0d23 7530 622d 7530 9121 2710 001f 7530 7d3f (6 Replies)
Discussion started by: Nayanajith
6 Replies

5. Programming

Convert HEX to EBCDIC IN C

i want to convert Hex value To EBCDIC value. i tried to convert hex to ascii and then to ebcdic but it doesn't give desired results . it doesn't give corresponding ebcdic value instead it gives some junk values. e.g; Hex EBCDIC ----------------- 81 a 82 b 83 c 84 d 85 e 86 f 87... (6 Replies)
Discussion started by: junaid.nehvi
6 Replies

6. Shell Programming and Scripting

HEX to DEC Conversion Error

I'm trying to convert hex to dec and with the help of output i need to do the process. If i execute the below code assetValue=8f assetNavigation=$(echo "ibase=16; "$assetValue"" | bc) echo $assetNavigation i'm getting the error below $ sh script.sh (standard_in) 1: syntax error... (1 Reply)
Discussion started by: Amutha
1 Replies

7. Shell Programming and Scripting

HEX to DEC Conversion

I'm trying to convert hex to dec and with the help of output i need to do the process. If i execute the below code assetValue=8f assetNavigation=$(echo "ibase=16; "$assetValue"" | bc) echo $assetNavigation i'm getting the error below $ sh script.sh (standard_in) 1: syntax error... (2 Replies)
Discussion started by: Amutha
2 Replies

8. Shell Programming and Scripting

Convert Hex - KSH

Hello, I woild like to convert hex on KSH not BASH: I tried to use: tmp=31 printf "\x"${tmp}"" it works on bash - Output is '1' but not on ksh. please advice on the right syntax. Thanks. (4 Replies)
Discussion started by: LiorAmitai
4 Replies

9. Shell Programming and Scripting

Convert hex to decimal

can someone help me in converting hex streams to decimal values using perl script Hex value: $my_hex_stream="0c07ac14001676"; Every hex value in the above stream should be converted in to decimal and separated by comma. The output should be: 12,07,172,20,00,22,118 (2 Replies)
Discussion started by: Arun_Linux
2 Replies

10. UNIX for Beginners Questions & Answers

How to generate adler32 stings that convert into hex stings in python 2.7?

I want to generate adler32 stings that converts into hex stings in python 2.7 (1 Reply)
Discussion started by: bigvito19
1 Replies
KERNEL_MOUNT(9) 					   BSD Kernel Developer's Manual					   KERNEL_MOUNT(9)

NAME
free_mntarg, kernel_mount, kernel_vmount, mount_arg, mount_argb, mount_argf, mount_argsu -- functions provided as part of the kernel mount interface SYNOPSIS
void free_mntarg(struct mntarg *ma); int kernel_mount(struct mntarg *ma, int flags); int kernel_vmount(int flags, ...); struct mntarg * mount_arg(struct mntarg *ma, const char *name, const void *val, int len); struct mntarg * mount_argb(struct mntarg *ma, int flag, const char *name); struct mntarg * mount_argf(struct mntarg *ma, const char *name, const char *fmt, ...); struct mntarg * mount_argsu(struct mntarg *ma, const char *name, const void *val, int len); DESCRIPTION
The kernel_mount() family of functions are provided as an API for building a list of mount arguments which will be used to mount file systems from inside the kernel. By accumulating a list of arguments, the API takes shape and provides the information necessary for the kernel to control the mount(8) utility. When an error occurs, the process will stop. This will not cause a panic(9). The header of the structure is stored in src/sys/kern/vfs_mount.c which permits automatic structure creation to ease the mount process. Mem- ory allocation must always be freed when the entire process is complete, it is an error otherwise. The free_mntarg() function is used to free or clear the mntarg structure. The kernel_mount() function pulls information from the structure to perform the mount request on a given file system. Additionally, the kernel_mount() function always calls the free_mntarg() function. If ma contains any error code generated during the construction, that code will be called and the file system mount will not be attempted. The kernel_vmount() is a function similar to printf(9) which is used to mount a file system. The mount_arg() function takes a plain argument and crafts parts of the structure with regards to various mount options. If the length is a value less than 0, strlen(3) is used. This argument will be referenced until either free_mntarg() or kernel_mount() is called. The mount_argb() function is used to add boolean arguments to the structure. The flag is the boolean value and name must start with "no", otherwise a panic will occur. The mount_argf() function adds printf(9) style arguments to the current structure. The mount_argsu() function will add arguments to the structure from a userland string. EXAMPLES
An example of the *_cmount() function: static int msdosfs_cmount(struct mntarg *ma, void *data, int flags, struct thread *td) { struct msdosfs_args args; int error; if (data == NULL) return (EINVAL); error = copyin(data, &args, sizeof(args)); if (error) return (error); ma = mount_argsu(ma, "from", args.fspec, MAXPATHLEN); ma = mount_arg(ma, "export", &args.export, sizeof(args.export)); ma = mount_argf(ma, "uid", "%d", args.uid); ma = mount_argf(ma, "gid", "%d", args.gid); ma = mount_argf(ma, "mask", "%d", args.mask); ma = mount_argf(ma, "dirmask", "%d", args.dirmask); ma = mount_argb(ma, args.flags & MSDOSFSMNT_SHORTNAME, "noshortname"); ma = mount_argb(ma, args.flags & MSDOSFSMNT_LONGNAME, "nolongname"); ma = mount_argb(ma, !(args.flags & MSDOSFSMNT_NOWIN95), "nowin95"); ma = mount_argb(ma, args.flags & MSDOSFSMNT_KICONV, "nokiconv"); ma = mount_argsu(ma, "cs_win", args.cs_win, MAXCSLEN); ma = mount_argsu(ma, "cs_dos", args.cs_dos, MAXCSLEN); ma = mount_argsu(ma, "cs_local", args.cs_local, MAXCSLEN); error = kernel_mount(ma, flags); return (error); } When working with kernel_vmount(), varargs must come in pairs, e.g., {name, value}. error = kernel_vmount( MNT_RDONLY, "fstype", vfsname, "fspath", "/", "from", path, NULL); SEE ALSO
VFS(9), VFS_MOUNT(9) HISTORY
The kernel_mount() family of functions and this manual page first appeared in FreeBSD 6.0. AUTHORS
The kernel_mount() family of functions and API was developed by Poul-Henning Kamp <phk@FreeBSD.org>. This manual page was written by Tom Rhodes <trhodes@FreeBSD.org>. BSD
December 13, 2004 BSD
All times are GMT -4. The time now is 01:32 PM.
Unix & Linux Forums Content Copyright 1993-2022. All Rights Reserved.
Privacy Policy