SlideShare a Scribd company logo
1 of 2
Download to read offline
bi Kon Jan 22 17i18z09 1996 1
/ •
* Filei Utnan.c
* AuthorI Itoltln BelX
* Copyright (c) 1993, 199< by Hotorola, Inc.
«
« PleaB« r«£or to ch^ter 2«9 (pages 48-49} of
* "The C ProgruMBing L«ngu*go" Second Edition by
* Brian W. X^rnlghon mnA Dmmim M. Rlt^l«
* tor r«l«v«nt bicJcground oo »ost of theaa routlnaa.
*
* Itta aucbor walconas any coBaantm/i^provMants
* you'd Ilka to a>^rasa partainlog to thla coda,
* particularly aa thay raXata to Incraaalng tha
* apaad of any of tha xoutlnaa.
•/
•Includa <atdlo.h>
/•
* gatblt8{x»p*n*dapth)
* X • tha muabar froai ii^lch blta will be extracted
* p » tha leftaoat poaltlon fron %rhlch bits will be extracted
* n• tha nuiftbar of blta that will be extracted
* depth m neatlng level of currant function call
*
'arror ciMcklng/noznallzing ia done on p and n
*!
unclgnad 9«tbita(unslgned x« unalgnad p, unalgnad n« unalgnad depth)
(
If (p < (alxeo((x|• 81)
• If tn <.(p• 1))
It (n > 0)
/* The tollovlng line differs from the boo)c because t)te shift operator
ght
, but
rc2
ed)
te
Id
« and » use ((right operand) % (sizeof(unsigned) * ()) for ri
operands greater than 31 or less than zero (if signed, which
doesn't apply to thia routine aince all paraitatars are unsigned
does apply in the general case of the shift operators) on a spa
instead of returning a number with all zeroa or ahitted in the
opposite direction. The nodiflcation of the line, however, is
particularly relevant for n » 32 on a sparc2i
-0 « n should e(]ual zero in ny opinion instead of ffffffff.
nie case tor shitting with a right operand less than zero (sign
is probably best handled by a se[arate routine that changes the
direction of the shifting then uses the absolute value of
the right e^perand if this value la less than 32. It the absolu
value ot the right operand la greater than 31, the routine ahou
return zero (again, ny opinion...). */
return (n < (sizeot(x) * S>) 7 ((X » (p 4- 1 - n}) t -(~Q « n)) i (x
» (p • 1 - n))I
else
fprintf(Btderr, *n •• 0 ERROR f%d la geCbltsI^ngetbita computed
with n -• ln*, depth)>
return getblts(x, p, 1, depth -t- l)i
) .- -
else
<
fprintf(stderr. *n > (p » 1) ERROR ilcl'hln g^bitslngetblta computed w
ieh n «• p » 1 - %dn*, depth, p -> l)i
return getbitslx, p. p + 1. depthD)
' >felse
(
fprintf(stderr, 'p >• (sizeof(x) « 1) ERROR ltd in getbitslngetbits
puted with p •> Bizeof(x) * S - 1• *dn*, depth, aizeof(x) * t - i)>
return getblts(x. sizeot(x) *(- 1, n, depth t i)i
)
)
(define getbitsl(a,b.c) getbits((a),(b),(c),1)
/•
• changabit(x.p,n,depth)•
• X • tbe nuiibsr in which a bit will be changed
• p - the location of the bit within x that will be changed
• n • tha value that the bit will be changed to --> 0 orl
• depth > nesting level ot current function call
•
< error chedcing/nonnallzing is dona on p and n
•/
unsigned changeblt(unalgned x. unsigned p, unsigned n, unsigned depth)
(
it (p < (sizeof(x) * 8))
if ((n ..0) II (n .. D)
return (n »- 0) 7 (x k -(01 « p)) i (x t (01 « p))i
else
(
fprintf(stderr, *(n l« 0) (n l> 1) ERROR ltd in changebitinchangei
computed with OxOl'getbitsl|%02x,%d,1) - *dn*, depth, x, p, 0x01 * getbitsli
P, l))i
return changeblt(x, p, OxOl " getbital(x, p, 1), depth t l)i
1
else
(
fprintt(stderr, "p >• (slzeof(x) • «) ERROR l%d in changabitInchaogebit
oi«>uted with p Bizeot{x) * t - 1 • tdn*. depth, slzeof(x)*•-!)>
return c^angabit(x< aizeotlx) *• - 1, n, depth * i)i
)
)
•define changebiti(a,b,c) changabit((a),(b),(c),1)
/»
* satblts(x,p,n,y,depth]
* X • the nuaber in which bits will be changed
* p• the leftmost position within x of bits to be changed
* n• the lamber ot rightmost bits in y that bits in x beginning at p
* will be changed to
* y• the number that will be the source tor changed blta tn x
* depth • neating level ot current function call
• error chec)cing/noraalizlng ia done on p and n
unsigned unsigned x, unsigned p, unsigned n. untJ^jStK^.V^ W»#i|8>e<l'^ajjltShJj
int it
«
ynmm
•..m
y? s.-
it (P < (SiZeOf(X) • t|) iS- , i.<ii ' * #
if (n <- (Blzeof(y) *8)) .
it (n <- (p + 11) rfA*
it (n > 0)
tor (1• Oi i < ni i++) • >
X.changebltKx, p• 1 - n• i,
retum x» ^ 'Mi-igSfU
) " "'
else
(
fprintf(Btderr, 'n -- 0 ERROR l%d in setbitsinsatbits comput<
with n •> in*, depth)I
return setbits(x, p, 1, y, depth « 1)i
)
Change Bits in Number

More Related Content

What's hot

Simulador carrera de caballos desarrollado en C++
Simulador carrera de caballos desarrollado en C++Simulador carrera de caballos desarrollado en C++
Simulador carrera de caballos desarrollado en C++Santiago Sarmiento
 
Exploring slides
Exploring slidesExploring slides
Exploring slidesakaptur
 
Q and erf functions
Q and erf functionsQ and erf functions
Q and erf functionsmohanadadnan
 
Ejercicios de la primera clase
Ejercicios de la primera claseEjercicios de la primera clase
Ejercicios de la primera claseIsrael Garciia
 
Gate level minimization (2nd update)
Gate level minimization (2nd update)Gate level minimization (2nd update)
Gate level minimization (2nd update)Aravir Rose
 
バイオインフォ分野におけるtidyなデータ解析の最新動向
バイオインフォ分野におけるtidyなデータ解析の最新動向バイオインフォ分野におけるtidyなデータ解析の最新動向
バイオインフォ分野におけるtidyなデータ解析の最新動向弘毅 露崎
 
The simplest existential graph system
The simplest existential graph systemThe simplest existential graph system
The simplest existential graph systemArmahedi Mahzar
 
Modular Macros for OCaml
Modular Macros for OCamlModular Macros for OCaml
Modular Macros for OCamlOCaml Labs
 

What's hot (17)

Cpp tutorial
Cpp tutorialCpp tutorial
Cpp tutorial
 
Share test
Share testShare test
Share test
 
Simulador carrera de caballos desarrollado en C++
Simulador carrera de caballos desarrollado en C++Simulador carrera de caballos desarrollado en C++
Simulador carrera de caballos desarrollado en C++
 
Py lecture5 python plots
Py lecture5 python plotsPy lecture5 python plots
Py lecture5 python plots
 
Exploring slides
Exploring slidesExploring slides
Exploring slides
 
Q and erf functions
Q and erf functionsQ and erf functions
Q and erf functions
 
Histogram
HistogramHistogram
Histogram
 
Code
CodeCode
Code
 
Ejercicios de la primera clase
Ejercicios de la primera claseEjercicios de la primera clase
Ejercicios de la primera clase
 
Gate level minimization (2nd update)
Gate level minimization (2nd update)Gate level minimization (2nd update)
Gate level minimization (2nd update)
 
Bubble Sort
Bubble SortBubble Sort
Bubble Sort
 
week-5x
week-5xweek-5x
week-5x
 
Trimming text
Trimming textTrimming text
Trimming text
 
バイオインフォ分野におけるtidyなデータ解析の最新動向
バイオインフォ分野におけるtidyなデータ解析の最新動向バイオインフォ分野におけるtidyなデータ解析の最新動向
バイオインフォ分野におけるtidyなデータ解析の最新動向
 
The simplest existential graph system
The simplest existential graph systemThe simplest existential graph system
The simplest existential graph system
 
Tools.cpp
Tools.cppTools.cpp
Tools.cpp
 
Modular Macros for OCaml
Modular Macros for OCamlModular Macros for OCaml
Modular Macros for OCaml
 

Similar to Change Bits in Number

Bab 6
Bab 6Bab 6
Bab 6Zinoa
 
06 Recursion in C.pptx
06 Recursion in C.pptx06 Recursion in C.pptx
06 Recursion in C.pptxMouDhara1
 
Dld unit-2-notes (1)
Dld unit-2-notes (1)Dld unit-2-notes (1)
Dld unit-2-notes (1)kamlimisty
 
OpenOpt の線形計画で圧縮センシング
OpenOpt の線形計画で圧縮センシングOpenOpt の線形計画で圧縮センシング
OpenOpt の線形計画で圧縮センシングToshihiro Kamishima
 
Bab 2
Bab 2Bab 2
Bab 2Zinoa
 
1531 fourier series- integrals and trans
1531 fourier series- integrals and trans1531 fourier series- integrals and trans
1531 fourier series- integrals and transDr Fereidoun Dejahang
 
El text.life science6.matsubayashi191120
El text.life science6.matsubayashi191120El text.life science6.matsubayashi191120
El text.life science6.matsubayashi191120RCCSRENKEI
 
Prob-Dist-Toll-Forecast-Uncertainty
Prob-Dist-Toll-Forecast-UncertaintyProb-Dist-Toll-Forecast-Uncertainty
Prob-Dist-Toll-Forecast-UncertaintyAnkoor Bhagat
 
Trial pahang 2014 spm add math k2 dan skema [scan]
Trial pahang 2014 spm add math k2 dan skema [scan]Trial pahang 2014 spm add math k2 dan skema [scan]
Trial pahang 2014 spm add math k2 dan skema [scan]Cikgu Pejal
 
Lecture12 pole-placement-multi-inputs-2020
Lecture12 pole-placement-multi-inputs-2020Lecture12 pole-placement-multi-inputs-2020
Lecture12 pole-placement-multi-inputs-2020cairo university
 
TMUA 2021 Paper 1 Solutions (Handwritten).pdf
TMUA 2021 Paper 1 Solutions (Handwritten).pdfTMUA 2021 Paper 1 Solutions (Handwritten).pdf
TMUA 2021 Paper 1 Solutions (Handwritten).pdfssuser625c41
 
13200836 solution-manual-process-dynamics-and-control-donald-r-coughanowr-130...
13200836 solution-manual-process-dynamics-and-control-donald-r-coughanowr-130...13200836 solution-manual-process-dynamics-and-control-donald-r-coughanowr-130...
13200836 solution-manual-process-dynamics-and-control-donald-r-coughanowr-130...nutkoon
 
Mathematical formula tables
Mathematical formula tablesMathematical formula tables
Mathematical formula tablesSaravana Selvan
 
Surge Swab pressure code
Surge Swab pressure codeSurge Swab pressure code
Surge Swab pressure codeANKIT KUKREJA
 
Model Based Fault Detection, Identification and Accommodation in Antilock Bra...
Model Based Fault Detection, Identification and Accommodation in Antilock Bra...Model Based Fault Detection, Identification and Accommodation in Antilock Bra...
Model Based Fault Detection, Identification and Accommodation in Antilock Bra...Behzad Samadi
 
University of manchester mathematical formula tables
University of manchester mathematical formula tablesUniversity of manchester mathematical formula tables
University of manchester mathematical formula tablesGaurav Vasani
 

Similar to Change Bits in Number (20)

Bab 6
Bab 6Bab 6
Bab 6
 
06 Recursion in C.pptx
06 Recursion in C.pptx06 Recursion in C.pptx
06 Recursion in C.pptx
 
Dld unit-2-notes (1)
Dld unit-2-notes (1)Dld unit-2-notes (1)
Dld unit-2-notes (1)
 
OpenOpt の線形計画で圧縮センシング
OpenOpt の線形計画で圧縮センシングOpenOpt の線形計画で圧縮センシング
OpenOpt の線形計画で圧縮センシング
 
Bab 2
Bab 2Bab 2
Bab 2
 
1531 fourier series- integrals and trans
1531 fourier series- integrals and trans1531 fourier series- integrals and trans
1531 fourier series- integrals and trans
 
Interpolation
InterpolationInterpolation
Interpolation
 
El text.life science6.matsubayashi191120
El text.life science6.matsubayashi191120El text.life science6.matsubayashi191120
El text.life science6.matsubayashi191120
 
Calculus III
Calculus IIICalculus III
Calculus III
 
Prob-Dist-Toll-Forecast-Uncertainty
Prob-Dist-Toll-Forecast-UncertaintyProb-Dist-Toll-Forecast-Uncertainty
Prob-Dist-Toll-Forecast-Uncertainty
 
Trial pahang 2014 spm add math k2 dan skema [scan]
Trial pahang 2014 spm add math k2 dan skema [scan]Trial pahang 2014 spm add math k2 dan skema [scan]
Trial pahang 2014 spm add math k2 dan skema [scan]
 
Lecture12 pole-placement-multi-inputs-2020
Lecture12 pole-placement-multi-inputs-2020Lecture12 pole-placement-multi-inputs-2020
Lecture12 pole-placement-multi-inputs-2020
 
TMUA 2021 Paper 1 Solutions (Handwritten).pdf
TMUA 2021 Paper 1 Solutions (Handwritten).pdfTMUA 2021 Paper 1 Solutions (Handwritten).pdf
TMUA 2021 Paper 1 Solutions (Handwritten).pdf
 
13200836 solution-manual-process-dynamics-and-control-donald-r-coughanowr-130...
13200836 solution-manual-process-dynamics-and-control-donald-r-coughanowr-130...13200836 solution-manual-process-dynamics-and-control-donald-r-coughanowr-130...
13200836 solution-manual-process-dynamics-and-control-donald-r-coughanowr-130...
 
Mathematical formula tables
Mathematical formula tablesMathematical formula tables
Mathematical formula tables
 
Deep learning
Deep learningDeep learning
Deep learning
 
Surge Swab pressure code
Surge Swab pressure codeSurge Swab pressure code
Surge Swab pressure code
 
Prelude to halide_public
Prelude to halide_publicPrelude to halide_public
Prelude to halide_public
 
Model Based Fault Detection, Identification and Accommodation in Antilock Bra...
Model Based Fault Detection, Identification and Accommodation in Antilock Bra...Model Based Fault Detection, Identification and Accommodation in Antilock Bra...
Model Based Fault Detection, Identification and Accommodation in Antilock Bra...
 
University of manchester mathematical formula tables
University of manchester mathematical formula tablesUniversity of manchester mathematical formula tables
University of manchester mathematical formula tables
 

More from Meltin Bell

Leaderboard12 17-13 patexia
Leaderboard12 17-13   patexiaLeaderboard12 17-13   patexia
Leaderboard12 17-13 patexiaMeltin Bell
 
Member directory2 8-14 patexia
Member directory2 8-14   patexiaMember directory2 8-14   patexia
Member directory2 8-14 patexiaMeltin Bell
 
National Society of Black Engineers 36th Annual Conference Toronto Presentation
National Society of Black Engineers 36th Annual Conference Toronto PresentationNational Society of Black Engineers 36th Annual Conference Toronto Presentation
National Society of Black Engineers 36th Annual Conference Toronto PresentationMeltin Bell
 
WIPO Linear Bit Counting Implementations
WIPO Linear Bit Counting ImplementationsWIPO Linear Bit Counting Implementations
WIPO Linear Bit Counting ImplementationsMeltin Bell
 
USPTO Linear Bit Counting Implementations
USPTO Linear Bit Counting ImplementationsUSPTO Linear Bit Counting Implementations
USPTO Linear Bit Counting ImplementationsMeltin Bell
 
Patent Pending Linear Bit Counting Implementations
Patent Pending Linear Bit Counting ImplementationsPatent Pending Linear Bit Counting Implementations
Patent Pending Linear Bit Counting ImplementationsMeltin Bell
 
Rule Evaluation on a Motorola SIMD
Rule Evaluation on a Motorola SIMDRule Evaluation on a Motorola SIMD
Rule Evaluation on a Motorola SIMDMeltin Bell
 

More from Meltin Bell (7)

Leaderboard12 17-13 patexia
Leaderboard12 17-13   patexiaLeaderboard12 17-13   patexia
Leaderboard12 17-13 patexia
 
Member directory2 8-14 patexia
Member directory2 8-14   patexiaMember directory2 8-14   patexia
Member directory2 8-14 patexia
 
National Society of Black Engineers 36th Annual Conference Toronto Presentation
National Society of Black Engineers 36th Annual Conference Toronto PresentationNational Society of Black Engineers 36th Annual Conference Toronto Presentation
National Society of Black Engineers 36th Annual Conference Toronto Presentation
 
WIPO Linear Bit Counting Implementations
WIPO Linear Bit Counting ImplementationsWIPO Linear Bit Counting Implementations
WIPO Linear Bit Counting Implementations
 
USPTO Linear Bit Counting Implementations
USPTO Linear Bit Counting ImplementationsUSPTO Linear Bit Counting Implementations
USPTO Linear Bit Counting Implementations
 
Patent Pending Linear Bit Counting Implementations
Patent Pending Linear Bit Counting ImplementationsPatent Pending Linear Bit Counting Implementations
Patent Pending Linear Bit Counting Implementations
 
Rule Evaluation on a Motorola SIMD
Rule Evaluation on a Motorola SIMDRule Evaluation on a Motorola SIMD
Rule Evaluation on a Motorola SIMD
 

Recently uploaded

Optimizing AI for immediate response in Smart CCTV
Optimizing AI for immediate response in Smart CCTVOptimizing AI for immediate response in Smart CCTV
Optimizing AI for immediate response in Smart CCTVshikhaohhpro
 
Short Story: Unveiling the Reasoning Abilities of Large Language Models by Ke...
Short Story: Unveiling the Reasoning Abilities of Large Language Models by Ke...Short Story: Unveiling the Reasoning Abilities of Large Language Models by Ke...
Short Story: Unveiling the Reasoning Abilities of Large Language Models by Ke...kellynguyen01
 
How To Troubleshoot Collaboration Apps for the Modern Connected Worker
How To Troubleshoot Collaboration Apps for the Modern Connected WorkerHow To Troubleshoot Collaboration Apps for the Modern Connected Worker
How To Troubleshoot Collaboration Apps for the Modern Connected WorkerThousandEyes
 
Der Spagat zwischen BIAS und FAIRNESS (2024)
Der Spagat zwischen BIAS und FAIRNESS (2024)Der Spagat zwischen BIAS und FAIRNESS (2024)
Der Spagat zwischen BIAS und FAIRNESS (2024)OPEN KNOWLEDGE GmbH
 
HR Software Buyers Guide in 2024 - HRSoftware.com
HR Software Buyers Guide in 2024 - HRSoftware.comHR Software Buyers Guide in 2024 - HRSoftware.com
HR Software Buyers Guide in 2024 - HRSoftware.comFatema Valibhai
 
Diamond Application Development Crafting Solutions with Precision
Diamond Application Development Crafting Solutions with PrecisionDiamond Application Development Crafting Solutions with Precision
Diamond Application Development Crafting Solutions with PrecisionSolGuruz
 
SyndBuddy AI 2k Review 2024: Revolutionizing Content Syndication with AI
SyndBuddy AI 2k Review 2024: Revolutionizing Content Syndication with AISyndBuddy AI 2k Review 2024: Revolutionizing Content Syndication with AI
SyndBuddy AI 2k Review 2024: Revolutionizing Content Syndication with AIABDERRAOUF MEHENNI
 
Russian Call Girls in Karol Bagh Aasnvi ➡️ 8264348440 💋📞 Independent Escort S...
Russian Call Girls in Karol Bagh Aasnvi ➡️ 8264348440 💋📞 Independent Escort S...Russian Call Girls in Karol Bagh Aasnvi ➡️ 8264348440 💋📞 Independent Escort S...
Russian Call Girls in Karol Bagh Aasnvi ➡️ 8264348440 💋📞 Independent Escort S...soniya singh
 
Advancing Engineering with AI through the Next Generation of Strategic Projec...
Advancing Engineering with AI through the Next Generation of Strategic Projec...Advancing Engineering with AI through the Next Generation of Strategic Projec...
Advancing Engineering with AI through the Next Generation of Strategic Projec...OnePlan Solutions
 
Software Quality Assurance Interview Questions
Software Quality Assurance Interview QuestionsSoftware Quality Assurance Interview Questions
Software Quality Assurance Interview QuestionsArshad QA
 
Active Directory Penetration Testing, cionsystems.com.pdf
Active Directory Penetration Testing, cionsystems.com.pdfActive Directory Penetration Testing, cionsystems.com.pdf
Active Directory Penetration Testing, cionsystems.com.pdfCionsystems
 
The Real-World Challenges of Medical Device Cybersecurity- Mitigating Vulnera...
The Real-World Challenges of Medical Device Cybersecurity- Mitigating Vulnera...The Real-World Challenges of Medical Device Cybersecurity- Mitigating Vulnera...
The Real-World Challenges of Medical Device Cybersecurity- Mitigating Vulnera...ICS
 
How To Use Server-Side Rendering with Nuxt.js
How To Use Server-Side Rendering with Nuxt.jsHow To Use Server-Side Rendering with Nuxt.js
How To Use Server-Side Rendering with Nuxt.jsAndolasoft Inc
 
5 Signs You Need a Fashion PLM Software.pdf
5 Signs You Need a Fashion PLM Software.pdf5 Signs You Need a Fashion PLM Software.pdf
5 Signs You Need a Fashion PLM Software.pdfWave PLM
 
Hand gesture recognition PROJECT PPT.pptx
Hand gesture recognition PROJECT PPT.pptxHand gesture recognition PROJECT PPT.pptx
Hand gesture recognition PROJECT PPT.pptxbodapatigopi8531
 
CALL ON ➥8923113531 🔝Call Girls Kakori Lucknow best sexual service Online ☂️
CALL ON ➥8923113531 🔝Call Girls Kakori Lucknow best sexual service Online  ☂️CALL ON ➥8923113531 🔝Call Girls Kakori Lucknow best sexual service Online  ☂️
CALL ON ➥8923113531 🔝Call Girls Kakori Lucknow best sexual service Online ☂️anilsa9823
 
Building Real-Time Data Pipelines: Stream & Batch Processing workshop Slide
Building Real-Time Data Pipelines: Stream & Batch Processing workshop SlideBuilding Real-Time Data Pipelines: Stream & Batch Processing workshop Slide
Building Real-Time Data Pipelines: Stream & Batch Processing workshop SlideChristina Lin
 
Unveiling the Tech Salsa of LAMs with Janus in Real-Time Applications
Unveiling the Tech Salsa of LAMs with Janus in Real-Time ApplicationsUnveiling the Tech Salsa of LAMs with Janus in Real-Time Applications
Unveiling the Tech Salsa of LAMs with Janus in Real-Time ApplicationsAlberto González Trastoy
 

Recently uploaded (20)

Optimizing AI for immediate response in Smart CCTV
Optimizing AI for immediate response in Smart CCTVOptimizing AI for immediate response in Smart CCTV
Optimizing AI for immediate response in Smart CCTV
 
Short Story: Unveiling the Reasoning Abilities of Large Language Models by Ke...
Short Story: Unveiling the Reasoning Abilities of Large Language Models by Ke...Short Story: Unveiling the Reasoning Abilities of Large Language Models by Ke...
Short Story: Unveiling the Reasoning Abilities of Large Language Models by Ke...
 
How To Troubleshoot Collaboration Apps for the Modern Connected Worker
How To Troubleshoot Collaboration Apps for the Modern Connected WorkerHow To Troubleshoot Collaboration Apps for the Modern Connected Worker
How To Troubleshoot Collaboration Apps for the Modern Connected Worker
 
Der Spagat zwischen BIAS und FAIRNESS (2024)
Der Spagat zwischen BIAS und FAIRNESS (2024)Der Spagat zwischen BIAS und FAIRNESS (2024)
Der Spagat zwischen BIAS und FAIRNESS (2024)
 
HR Software Buyers Guide in 2024 - HRSoftware.com
HR Software Buyers Guide in 2024 - HRSoftware.comHR Software Buyers Guide in 2024 - HRSoftware.com
HR Software Buyers Guide in 2024 - HRSoftware.com
 
Diamond Application Development Crafting Solutions with Precision
Diamond Application Development Crafting Solutions with PrecisionDiamond Application Development Crafting Solutions with Precision
Diamond Application Development Crafting Solutions with Precision
 
SyndBuddy AI 2k Review 2024: Revolutionizing Content Syndication with AI
SyndBuddy AI 2k Review 2024: Revolutionizing Content Syndication with AISyndBuddy AI 2k Review 2024: Revolutionizing Content Syndication with AI
SyndBuddy AI 2k Review 2024: Revolutionizing Content Syndication with AI
 
Russian Call Girls in Karol Bagh Aasnvi ➡️ 8264348440 💋📞 Independent Escort S...
Russian Call Girls in Karol Bagh Aasnvi ➡️ 8264348440 💋📞 Independent Escort S...Russian Call Girls in Karol Bagh Aasnvi ➡️ 8264348440 💋📞 Independent Escort S...
Russian Call Girls in Karol Bagh Aasnvi ➡️ 8264348440 💋📞 Independent Escort S...
 
Advancing Engineering with AI through the Next Generation of Strategic Projec...
Advancing Engineering with AI through the Next Generation of Strategic Projec...Advancing Engineering with AI through the Next Generation of Strategic Projec...
Advancing Engineering with AI through the Next Generation of Strategic Projec...
 
Software Quality Assurance Interview Questions
Software Quality Assurance Interview QuestionsSoftware Quality Assurance Interview Questions
Software Quality Assurance Interview Questions
 
Active Directory Penetration Testing, cionsystems.com.pdf
Active Directory Penetration Testing, cionsystems.com.pdfActive Directory Penetration Testing, cionsystems.com.pdf
Active Directory Penetration Testing, cionsystems.com.pdf
 
The Real-World Challenges of Medical Device Cybersecurity- Mitigating Vulnera...
The Real-World Challenges of Medical Device Cybersecurity- Mitigating Vulnera...The Real-World Challenges of Medical Device Cybersecurity- Mitigating Vulnera...
The Real-World Challenges of Medical Device Cybersecurity- Mitigating Vulnera...
 
How To Use Server-Side Rendering with Nuxt.js
How To Use Server-Side Rendering with Nuxt.jsHow To Use Server-Side Rendering with Nuxt.js
How To Use Server-Side Rendering with Nuxt.js
 
5 Signs You Need a Fashion PLM Software.pdf
5 Signs You Need a Fashion PLM Software.pdf5 Signs You Need a Fashion PLM Software.pdf
5 Signs You Need a Fashion PLM Software.pdf
 
Hand gesture recognition PROJECT PPT.pptx
Hand gesture recognition PROJECT PPT.pptxHand gesture recognition PROJECT PPT.pptx
Hand gesture recognition PROJECT PPT.pptx
 
CALL ON ➥8923113531 🔝Call Girls Kakori Lucknow best sexual service Online ☂️
CALL ON ➥8923113531 🔝Call Girls Kakori Lucknow best sexual service Online  ☂️CALL ON ➥8923113531 🔝Call Girls Kakori Lucknow best sexual service Online  ☂️
CALL ON ➥8923113531 🔝Call Girls Kakori Lucknow best sexual service Online ☂️
 
Vip Call Girls Noida ➡️ Delhi ➡️ 9999965857 No Advance 24HRS Live
Vip Call Girls Noida ➡️ Delhi ➡️ 9999965857 No Advance 24HRS LiveVip Call Girls Noida ➡️ Delhi ➡️ 9999965857 No Advance 24HRS Live
Vip Call Girls Noida ➡️ Delhi ➡️ 9999965857 No Advance 24HRS Live
 
Building Real-Time Data Pipelines: Stream & Batch Processing workshop Slide
Building Real-Time Data Pipelines: Stream & Batch Processing workshop SlideBuilding Real-Time Data Pipelines: Stream & Batch Processing workshop Slide
Building Real-Time Data Pipelines: Stream & Batch Processing workshop Slide
 
Call Girls In Mukherjee Nagar 📱 9999965857 🤩 Delhi 🫦 HOT AND SEXY VVIP 🍎 SE...
Call Girls In Mukherjee Nagar 📱  9999965857  🤩 Delhi 🫦 HOT AND SEXY VVIP 🍎 SE...Call Girls In Mukherjee Nagar 📱  9999965857  🤩 Delhi 🫦 HOT AND SEXY VVIP 🍎 SE...
Call Girls In Mukherjee Nagar 📱 9999965857 🤩 Delhi 🫦 HOT AND SEXY VVIP 🍎 SE...
 
Unveiling the Tech Salsa of LAMs with Janus in Real-Time Applications
Unveiling the Tech Salsa of LAMs with Janus in Real-Time ApplicationsUnveiling the Tech Salsa of LAMs with Janus in Real-Time Applications
Unveiling the Tech Salsa of LAMs with Janus in Real-Time Applications
 

Change Bits in Number

  • 1. bi Kon Jan 22 17i18z09 1996 1 / • * Filei Utnan.c * AuthorI Itoltln BelX * Copyright (c) 1993, 199< by Hotorola, Inc. « « PleaB« r«£or to ch^ter 2«9 (pages 48-49} of * "The C ProgruMBing L«ngu*go" Second Edition by * Brian W. X^rnlghon mnA Dmmim M. Rlt^l« * tor r«l«v«nt bicJcground oo »ost of theaa routlnaa. * * Itta aucbor walconas any coBaantm/i^provMants * you'd Ilka to a>^rasa partainlog to thla coda, * particularly aa thay raXata to Incraaalng tha * apaad of any of tha xoutlnaa. •/ •Includa <atdlo.h> /• * gatblt8{x»p*n*dapth) * X • tha muabar froai ii^lch blta will be extracted * p » tha leftaoat poaltlon fron %rhlch bits will be extracted * n• tha nuiftbar of blta that will be extracted * depth m neatlng level of currant function call * 'arror ciMcklng/noznallzing ia done on p and n *! unclgnad 9«tbita(unslgned x« unalgnad p, unalgnad n« unalgnad depth) ( If (p < (alxeo((x|• 81) • If tn <.(p• 1)) It (n > 0) /* The tollovlng line differs from the boo)c because t)te shift operator ght , but rc2 ed) te Id « and » use ((right operand) % (sizeof(unsigned) * ()) for ri operands greater than 31 or less than zero (if signed, which doesn't apply to thia routine aince all paraitatars are unsigned does apply in the general case of the shift operators) on a spa instead of returning a number with all zeroa or ahitted in the opposite direction. The nodiflcation of the line, however, is particularly relevant for n » 32 on a sparc2i -0 « n should e(]ual zero in ny opinion instead of ffffffff. nie case tor shitting with a right operand less than zero (sign is probably best handled by a se[arate routine that changes the direction of the shifting then uses the absolute value of the right e^perand if this value la less than 32. It the absolu value ot the right operand la greater than 31, the routine ahou return zero (again, ny opinion...). */ return (n < (sizeot(x) * S>) 7 ((X » (p 4- 1 - n}) t -(~Q « n)) i (x » (p • 1 - n))I else fprintf(Btderr, *n •• 0 ERROR f%d la geCbltsI^ngetbita computed with n -• ln*, depth)> return getblts(x, p, 1, depth -t- l)i ) .- - else < fprintf(stderr. *n > (p » 1) ERROR ilcl'hln g^bitslngetblta computed w ieh n «• p » 1 - %dn*, depth, p -> l)i return getbitslx, p. p + 1. depthD) ' >felse ( fprintf(stderr, 'p >• (sizeof(x) « 1) ERROR ltd in getbitslngetbits puted with p •> Bizeof(x) * S - 1• *dn*, depth, aizeof(x) * t - i)> return getblts(x. sizeot(x) *(- 1, n, depth t i)i ) ) (define getbitsl(a,b.c) getbits((a),(b),(c),1) /• • changabit(x.p,n,depth)• • X • tbe nuiibsr in which a bit will be changed • p - the location of the bit within x that will be changed • n • tha value that the bit will be changed to --> 0 orl • depth > nesting level ot current function call • < error chedcing/nonnallzing is dona on p and n •/ unsigned changeblt(unalgned x. unsigned p, unsigned n, unsigned depth) ( it (p < (sizeof(x) * 8)) if ((n ..0) II (n .. D) return (n »- 0) 7 (x k -(01 « p)) i (x t (01 « p))i else ( fprintf(stderr, *(n l« 0) (n l> 1) ERROR ltd in changebitinchangei computed with OxOl'getbitsl|%02x,%d,1) - *dn*, depth, x, p, 0x01 * getbitsli P, l))i return changeblt(x, p, OxOl " getbital(x, p, 1), depth t l)i 1 else ( fprintt(stderr, "p >• (slzeof(x) • «) ERROR l%d in changabitInchaogebit oi«>uted with p Bizeot{x) * t - 1 • tdn*. depth, slzeof(x)*•-!)> return c^angabit(x< aizeotlx) *• - 1, n, depth * i)i ) ) •define changebiti(a,b,c) changabit((a),(b),(c),1) /» * satblts(x,p,n,y,depth] * X • the nuaber in which bits will be changed * p• the leftmost position within x of bits to be changed * n• the lamber ot rightmost bits in y that bits in x beginning at p * will be changed to * y• the number that will be the source tor changed blta tn x * depth • neating level ot current function call • error chec)cing/noraalizlng ia done on p and n unsigned unsigned x, unsigned p, unsigned n. untJ^jStK^.V^ W»#i|8>e<l'^ajjltShJj int it « ynmm •..m y? s.- it (P < (SiZeOf(X) • t|) iS- , i.<ii ' * # if (n <- (Blzeof(y) *8)) . it (n <- (p + 11) rfA* it (n > 0) tor (1• Oi i < ni i++) • > X.changebltKx, p• 1 - n• i, retum x» ^ 'Mi-igSfU ) " "' else ( fprintf(Btderr, 'n -- 0 ERROR l%d in setbitsinsatbits comput< with n •> in*, depth)I return setbits(x, p, 1, y, depth « 1)i )