From: Kurtis Rader <krader@skepticism.us>
To: dominik.vogt@gmx.de, Zsh Users <zsh-users@zsh.org>
Subject: Re: Determining the length of "long"?
Date: Thu, 11 Sep 2014 19:58:29 -0700 [thread overview]
Message-ID: <CABx2=D_PBnmTFCsDvZBZqT0bLOAzOgT5at9XhfWPHG3=bswpbw@mail.gmail.com> (raw)
In-Reply-To: <20140911213608.GA1029@gmx.de>
[-- Attachment #1: Type: text/plain, Size: 1122 bytes --]
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@gmx.de> 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
next prev parent reply other threads:[~2014-09-12 2:58 UTC|newest]
Thread overview: 13+ messages / expand[flat|nested] mbox.gz Atom feed top
2014-09-11 21:36 Dominik Vogt
2014-09-12 2:58 ` Kurtis Rader [this message]
2014-09-12 4:39 ` Bart Schaefer
2014-09-12 8:42 ` Dominik Vogt
2014-09-12 13:17 ` Kurtis Rader
2014-09-12 23:16 ` Bart Schaefer
2014-09-12 23:42 ` Dominik Vogt
2014-09-13 0:17 ` Bart Schaefer
2014-09-12 8:51 ` Peter Stephenson
2014-09-12 16:17 ` Roman Neuhauser
2014-09-12 17:04 ` Dominik Vogt
2014-09-12 18:10 ` Roman Neuhauser
2014-09-12 18:50 ` Dominik Vogt
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to='CABx2=D_PBnmTFCsDvZBZqT0bLOAzOgT5at9XhfWPHG3=bswpbw@mail.gmail.com' \
--to=krader@skepticism.us \
--cc=dominik.vogt@gmx.de \
--cc=zsh-users@zsh.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
Code repositories for project(s) associated with this public inbox
https://git.vuxu.org/mirror/zsh/
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).