473,768 Members | 1,937 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

extracting front bits from an unsigned long long?

Hi, suppose I have an unsigned long long. I would like to extract
the front 'n' bits of this value and convert them into an integer.
For example, if I extract the first 3 bits, I would get an int between
0 and 7 (=2^3-1). Could someone please help out?

I can assume the largest returned value fits in an int. Also,
I'm on a big-endian PPC (AIX), in case that matters.

Ideally, I'd like to implement a prototype like:
int extractFrontBit s(unsigned long long value, int num_bits);

Nov 15 '05
36 5316
In article <11************ **********@g14g 2000cwa.googleg roups.com>,
sl*******@yahoo .com <sl*******@gmai l.com> wrote:
Haven't had much experience with non-native english speakers have you?
In a lot of eastern languages front and first are synonyms.


They are often synonyms in English. In particular, when objects are
moving along a path, the front one will be the first one. But when
(as is the case here) the idea is of looking at a static sequence of
objects, the situation is less clear. "3" is the first digit of 315
when you read or write it, but if you imagine the sequence itself
pointing in left-to-right order (i.e. English reading order) then you
would call "5" the front digit.

In such circumstances it is better to be explicit and say "leftmost",
or if you don't even want to commit to a particular writing direction,
"most significant".

-- Richard
Nov 15 '05 #31
On 12 Nov 2005 14:41:20 -0800, in comp.lang.c , "sl*******@yaho o.com"
<sl*******@gmai l.com> wrote:
Haven't had much experience with non-native english speakers have you?
No, I only worked for a French bank for 10 years. Plus let me tell
you, working in London is like working in the tower of babel..
In a lot of eastern languages front and first are synonyms.


So what?
--
Mark McIntyre
CLC FAQ <http://www.eskimo.com/~scs/C-faq/top.html>
CLC readme: <http://www.ungerhu.com/jxh/clc.welcome.txt >

----== Posted via Newsfeeds.Com - Unlimited-Unrestricted-Secure Usenet News==----
http://www.newsfeeds.com The #1 Newsgroup Service in the World! 120,000+ Newsgroups
----= East and West-Coast Server Farms - Total Privacy via Encryption =----
Nov 15 '05 #32
sl*******@yahoo .com wrote:

Mark McIntyre wrote:
On 11 Nov 2005 12:08:47 -0800, in comp.lang.c , "Digital Puer"
<di**********@h otmail.com> wrote:
Just for my edification,
how else would one interpret "front bits"?
I wouldn't
I didn't.
- it doesn't mean anything to me.
Me neither.
Arrays of bits don't have backs, fronts or sides...
E.g. the front digit of 543 is 5.


First perhaps. Leftmost perhaps. Front no.


I would call that, the most significant digit.
Haven't had much experience with non-native english speakers have you?
In a lot of eastern languages front and first are synonyms.


It seemed to me, that given a choice between bit0 and bit1,
that bit0, the low order bit, would be the first one.

But I often have trouble understanding plain English,
and yes, it is my only language.

I like to code but I don't enjoy extracting specifications.
I really would have to be paid, in order to do that.

When somebody posts a question and I don't understand it right,
then I answer it wrong.

When somebody posts a question and I do understand it right,
then my chances are better.

--
pete
Nov 15 '05 #33
sl*******@yahoo .com wrote:
Mark McIntyre wrote:
On 11 Nov 2005 12:08:47 -0800, in comp.lang.c , "Digital Puer"
<di**********@h otmail.com> wrote:
Just for my edification, how else would one interpret "front bits"?

I wouldn't - it doesn't mean anything to me. Arrays of bits don't have
backs, fronts or sides...
E.g. the front digit of 543 is 5.

First perhaps. Leftmost perhaps. Front no.


Haven't had much experience with non-native english speakers have you?
In a lot of eastern languages front and first are synonyms.


That's as maybe, but this is not one of those eastern languages.

I would not use front or first. I would possibly use left, but generally
highest or most significant.
--
Flash Gordon
Living in interesting times.
Although my email address says spam, it is real and I read it.
Nov 15 '05 #34

Mark McIntyre wrote:
On 12 Nov 2005 14:41:20 -0800, in comp.lang.c , "sl*******@yaho o.com"
<sl*******@gmai l.com> wrote:
In a lot of eastern languages front and first are synonyms.


So what?


So, to a lot of people like me, who often 'think' in our native
language and then translate into english we often say front instead of
first. In Malay for instance, first relates to chronological sequence
and front relates to spatial sequence. A sequence of bits in a register
or in memory is spatial. I'm not saying you're wrong. As in english it
IS better to use 'first'. Actually it is better to use 'most
significant'. My point is simply that not everyone thinks that way.

OK, so there was a misunderstandin g. It has been resolved. The OP is
happy. Move along now...

Nov 15 '05 #35
In article <dl***********@ pc-news.cogsci.ed. ac.uk> ri*****@cogsci. ed.ac.uk (Richard Tobin) writes:
In article <11************ **********@g14g 2000cwa.googleg roups.com>,
sl*******@yahoo .com <sl*******@gmai l.com> wrote:
Haven't had much experience with non-native english speakers have you?
In a lot of eastern languages front and first are synonyms.
.... In such circumstances it is better to be explicit and say "leftmost",
or if you don't even want to commit to a particular writing direction,
"most significant".


And both do not really convey the meaning of the OP. Which was (as I
understand it now) the sequence of 'k' bits starting at the first 1 bit
in the binary representation of the number. Or (in other terms) the
first 'k' bits if leading 0's are ignored.
--
dik t. winter, cwi, kruislaan 413, 1098 sj amsterdam, nederland, +31205924131
home: bovenover 215, 1025 jn amsterdam, nederland; http://www.cwi.nl/~dik/
Nov 15 '05 #36
On 12 Nov 2005 16:41:19 -0800, in comp.lang.c , "sl*******@yaho o.com"
<sl*******@gmai l.com> wrote:

Mark McIntyre wrote:
On 12 Nov 2005 14:41:20 -0800, in comp.lang.c , "sl*******@yaho o.com"
<sl*******@gmai l.com> wrote:
>In a lot of eastern languages front and first are synonyms.
So what?


So, to a lot of people like me, who often 'think' in our native
language and then translate into english we often say front instead of
first.


If you cast your mind back, you'll recall that the question I was
answering was "how would you interpret front bits". Not unnaturally I
expressed my opinion of how I'd intrepret it, and what I'd call the
leftmost bit of eg 543.

It was NOT "how would you expect someone with limited grasp of English
to translate their own word for 'first' into English". So I didn't
answer this question.

So you see, I consider your comment utterly bloody irrelevant!
OK, so there was a misunderstandin g. It has been resolved.


I do hope so
--
Mark McIntyre
CLC FAQ <http://www.eskimo.com/~scs/C-faq/top.html>
CLC readme: <http://www.ungerhu.com/jxh/clc.welcome.txt >

----== Posted via Newsfeeds.Com - Unlimited-Unrestricted-Secure Usenet News==----
http://www.newsfeeds.com The #1 Newsgroup Service in the World! 120,000+ Newsgroups
----= East and West-Coast Server Farms - Total Privacy via Encryption =----
Nov 15 '05 #37

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

4
5518
by: Simon | last post by:
Hi, I am reading a file that contains a bunch of unsigned longs. The number itself is broken down in bits, for example bit 31-24 is a certain code and bit 7-6 represents a certain state. am I right in doing the following // read the unsigned long from the file
40
5721
by: aku | last post by:
I'm looking for the absolute fastest way to count the nr of bits that are set to "1" in a string. Presumably I then first need the fastest way to do this in a byte. I think this is it, but welcome any improvements: i = 0; if (g && 1) i++; if (g && 2) i++;
7
4807
by: sathyashrayan | last post by:
Group, Following function will check weather a bit is set in the given variouble x. int bit_count(long x) { int n = 0; /* ** The loop will execute once for each bit of x set,
17
1857
by: James S. Singleton | last post by:
Let S be a pointer to a bytestring of length L. I would like to extract 4 bytes from S at the location p = S + d, with 0 < d < L - 4, and store them into an unsigned int. I am looking for suggestions on how to do this 1) In portable ANSI C. 2) As efficiently as possible. 3) Taking full account of the potential data alignment and endianness issues that this action must tackle.
0
9407
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
10018
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
1
9964
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
9845
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
1
7387
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
5285
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
0
5425
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
3933
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
3
2808
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.