From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 9611 invoked by alias); 12 Sep 2014 04:39:01 -0000 Mailing-List: contact zsh-users-help@zsh.org; run by ezmlm Precedence: bulk X-No-Archive: yes List-Id: Zsh Users List List-Post: List-Help: X-Seq: 19066 Received: (qmail 27050 invoked from network); 12 Sep 2014 04:39:00 -0000 X-Spam-Checker-Version: SpamAssassin 3.3.2 (2011-06-06) on f.primenet.com.au X-Spam-Level: X-Spam-Status: No, score=-1.9 required=5.0 tests=BAYES_00,RCVD_IN_DNSWL_NONE autolearn=ham version=3.3.2 From: Bart Schaefer Message-id: <140911213901.ZM21898@torch.brasslantern.com> Date: Thu, 11 Sep 2014 21:39:01 -0700 In-reply-to: <20140911213608.GA1029@gmx.de> Comments: In reply to Dominik Vogt "Determining the length of "long"?" (Sep 11, 10:36pm) References: <20140911213608.GA1029@gmx.de> X-Mailer: OpenZMail Classic (0.9.2 24April2005) To: Zsh Users Subject: Re: Determining the length of "long"? MIME-version: 1.0 Content-type: text/plain; charset=us-ascii On Sep 11, 10:36pm, Dominik Vogt 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 Kurtis mentioned, the shell really isn't the right tool for this, but: if (( ${#:-"$(( [#2] (1<<31)))"} > ${#:-"$(( [#2] (1<<63)))"} )) then print "zsh integer type is 32 bits" elif (( ${#:-"$(( [#2] (1<<63)))"} > ${#:-"$(( [#2] (1<<64)))"} )) then print "zsh integer type is 64 bits" else print "zsh integer type is more than 64 bits" fi } As an alternative, is there a direct way to print out a "long" } integer value as binary bytes in host byte order? There's no guarantee that zsh's integer type is "long", so no, there is not. You can try fiddling with bitwise operators, e.g.: setopt C_BASES integer i=0x12345 while (( i )) { printf '\\\\x%x\n' $(( [#16] (i & 0xff) )) (( i = i >> 8 )) } Printing the zero bytes and not messing up the byte order is left as an exercise for the reader.