Zsh Mailing List Archive
Messages sorted by: Reverse Date, Date, Thread, Author

Re: Determining the length of "long"?



There may be a way but why? A command shell is the wrong tool for that task.

You don't need to compile a C program to do this. If you have perl or
python it's an almost trivial problem. For example,

#!/usr/bin/env python
import ctypes

l = ctypes.c_long(0x12345)
print(ctypes.sizeof(l))

b = ctypes.string_at(ctypes.addressof(l), ctypes.sizeof(l))
print(''.join('\\x{:02x}'.format(ord(x)) for x in b))


On Thu, Sep 11, 2014 at 2:36 PM, Dominik Vogt <dominik.vogt@xxxxxx> wrote:

> Is there a way to determine the length of the C type long from
> inside a zsh script (without using external programs, of course).
>
> As an alternative, is there a direct way to print out a "long"
> integer value as binary bytes in host byte order?
>
> I.e. given a value, say 0x12345, I need to print that as
>
>   \\x00\\x01\\x23\\x45
>
> on a 32 bit platform, and as
>
>   \\x00\\x00\\x00\\x00\\x00\\x01\\x23\\x45
>
> on a 64 bit platform (possibly in reverse byte order, depending on
> the hardware).
>
> Ciao
>
> Dominik ^_^  ^_^
>
> --
>
> Dominik Vogt
>
>
>


-- 
Kurtis Rader
Caretaker of the exceptional canines Junior and Hank


Messages sorted by: Reverse Date, Date, Thread, Author