Sponsored Content
Top Forums Programming How to extract operand size in bits of a C program? Post 302978998 by Don Cragun on Monday 8th of August 2016 03:19:23 AM
Old 08-08-2016
OK. That is a different question totally unrelated to the title of this thread. The highest bit set in a non-negative integer number for a number that will fit in a C signed long integer value can be found in a shell that conforms to the POSIX standards using something like:
Code:
printf 'Enter non-negative integer (ctl-D to exit): '
while read -r n
do	printf 'Highest bit set in %s is ' "$n"
	bits=0
	while [ "$n" -gt 0 ]
	do	bits=$((bits + 1))
		n=$((n / 2))
	done
	printf '%d.\n' $bits
	printf 'Enter another non-negative integer (ctl-D to exit): '
done
printf '\nGoodbye\n'

Of course, this doesn't do any validity checking on the values entered and may die a horrible death if a non-numeric entry or an out-of-range numeric entry is given. With a 1993 or later version of the Korn shell, you might be able to process numbers considerably larger than 2**63 - 1.
This User Gave Thanks to Don Cragun For This Post:
 

8 More Discussions You Might Find Interesting

1. UNIX for Dummies Questions & Answers

Changing 24 bits to 8 bits display

Hello all, I was wondering if anyone can tell me how to change 24 bits depth display to 8 bits depth display for Sun Ultra1, running Solaris 8? THANKS in advance. I think that the command is ffbconfig, but it has nothing about depth. (4 Replies)
Discussion started by: larry
4 Replies

2. Solaris

How to know the size of the program currently executing in memory

hey everybody, i am currently working on solaris 10 os on a m5000 server. my problem is when i want the exact size of a program in execution, i am unable to do it. earlier i thought the RSS field of prstat but because of its large size it cant be the size. pmap -x shows some output but it includes... (2 Replies)
Discussion started by: aryansheikh
2 Replies

3. UNIX for Dummies Questions & Answers

32 bits procesaor with 64 bits Solaris

people i have a problem i have a 32 bits sparc processor, and solaris 64 bits processor, i install a oracle data base 64 bits, but my oracle will not run because my processor is from 32 bits this is ok??, i know if i have x86 i cannot install a 64 bits operatin system in a 32 bits processor. ... (0 Replies)
Discussion started by: enkei17
0 Replies

4. Programming

Compiling a 64 bits program using gcc

Hi Everyone, I can ask what is the option to compile a 64 bits program using gcc. I have looked everywhere but can't find it. Before I used to use cc and the -q64 flag was the option to generate the 64 bits binary. Can anyone tell me what is the flags when using gcc. Thanks...... (3 Replies)
Discussion started by: arizah
3 Replies

5. What is on Your Mind?

Place Bits & Win Bits!!! - 17th Annual Satellite Awards

Ten movies have been nominated as best motion picture by the International Press Academy, presentation of the 2012 Satellite Awards will be held on 16th December at Los Angeles, CA. Place your bits here on one of the below nominated movie of your choice:- Argo ... (0 Replies)
Discussion started by: Yoda
0 Replies

6. UNIX Desktop Questions & Answers

Knowing the size and location of variables in a C program

So I need some help with this. Pardon me if I'm posting in the wrong forum, after some googling for my answer and finding nothing I found this forum. It seemed appropriate for what I was seeking. I just didnt find a forum that concerned the use of GDB. I'm learning to use the C language and GDB.... (2 Replies)
Discussion started by: Cambria
2 Replies

7. Programming

Size of memory used by a program

Hello, Here is a portion of my code: a=(int *) malloc(dim*dim*sizeof(int)); b=(int *) malloc(dim*dim*sizeof(int)); c=(int *) malloc(dim*dim*sizeof(int)); for(i=0;i<dim;i++) for(j=0;j<dim;j++) c= rand(); for(i=0;i<dim;i++) for(j=0;j<dim;j++) b=rand(); ... (6 Replies)
Discussion started by: chercheur111
6 Replies

8. UNIX for Beginners Questions & Answers

How do I determine the best number to use for the bs (block size) operand of the dd command?

When I create a bootable Linux distro installation USB drive, I use this command: sudo dd if=/Path/to/linux_distro.iso of=/dev/rdisk<disk number> bs=<number of bytes> When I look it up, I've seen variations of people choosing 4M, and I think 8M, 2M, and maybe even 1M. If I leave the operand... (4 Replies)
Discussion started by: Quenz
4 Replies
type(1) 							   User Commands							   type(1)

NAME
type - write a description of command type SYNOPSIS
type name... DESCRIPTION
The type utility indicates how each name operand would be interpreted if used as a command. type displays information about each operand identifying the operand as a shell built-in, function, alias, hashed command, or keyword, and where applicable, may display the operand's path name. There is also a shell built-in version of type that is similar to the type utility. OPERANDS
The following operand is supported: name A name to be interpreted. ENVIRONMENT VARIABLES
See environ(5) for descriptions of the following environment variables that affect the execution of type: LANG, LC_ALL, LC_CTYPE, LC_MES- SAGES, and NLSPATH. PATH Determine the location of name. EXIT STATUS
The following exit values are returned: 0 Successful completion. >0 An error occurred. ATTRIBUTES
See attributes(5) for descriptions of the following attributes: +-----------------------------+-----------------------------+ | ATTRIBUTE TYPE | ATTRIBUTE VALUE | +-----------------------------+-----------------------------+ |Availability |SUNWcsu | +-----------------------------+-----------------------------+ |Interface Stability |Standard | +-----------------------------+-----------------------------+ SEE ALSO
typeset(1), attributes(5), environ(5), standards(5) SunOS 5.10 1 Feb 1995 type(1)
All times are GMT -4. The time now is 09:59 AM.
Unix & Linux Forums Content Copyright 1993-2022. All Rights Reserved.
Privacy Policy