Click here to Skip to main content
15,913,773 members

Welcome to the Lounge

   

For discussing anything related to a software developer's life but is not for programming questions. Got a programming question?

The Lounge is rated Safe For Work. If you're about to post something inappropriate for a shared office environment, then don't post it. No ads, no abuse, and no programming questions. Trolling, (political, climate, religious or whatever) will result in your account being removed.

 
GeneralRe: So there I was... Pin
Michael Martin5-Oct-17 0:59
professionalMichael Martin5-Oct-17 0:59 
GeneralRe: So there I was... Pin
User 84204-Oct-17 10:53
User 84204-Oct-17 10:53 
GeneralRe: So there I was... Pin
Jörgen Andersson4-Oct-17 19:42
professionalJörgen Andersson4-Oct-17 19:42 
GeneralRe: So there I was... Pin
Nicholas Marty5-Oct-17 1:05
professionalNicholas Marty5-Oct-17 1:05 
GeneralRe: So there I was... Pin
Daniel Pfeffer5-Oct-17 9:38
professionalDaniel Pfeffer5-Oct-17 9:38 
GeneralRe: So there I was... Pin
Vark1114-Oct-17 9:27
Vark1114-Oct-17 9:27 
GeneralRe: So there I was... Pin
GKP19924-Oct-17 20:28
professionalGKP19924-Oct-17 20:28 
GeneralRe: So there I was... Pin
kalberts5-Oct-17 0:17
kalberts5-Oct-17 0:17 
If you hadn't mentioned SQL (obligatory Geek & Poke: Simply exåøaomed: SQL[^] I would have understood your worries.

Historically, databases (and Cobol Smile | :) ) primary belongs in the domain of administration, management and economy. You work with dollars and cents, maybe tenth of a cent as well, but that is exact. If you split a bill of $3.30 on three persons, $1.10 on each, and collect the three $3.30 for giving it to the taxi driver, he receives exactly $3.30. If you do it in the engineering style floating point numbers, the amount that the taxi driver rececives makes you associate to Pentium FDIV bug - Wikipedia[^]. Accountants are as mad at floating point inexactness as engineers are at the Intel bug!

So, at least since around 1960, developers of business software (as well as computer manufacturers making machines for executing that software) have been storing values in Binary-coded decimal[^] (BCD) format: Each binary digit takes up 4 bits. Since this gives 16 possibilities, the excess six are usually defined to represent numeric sign (+/-), currency symbol etc.

Note that conversion from ASCII to BCD digits is a simple masking (AND) operation, from BCD to ASCII setting a couple bits (OR). Most machines/libraries can handle BCD both eight bits to the digit (after simple ASCII masking) and four bits to the digit (sometimes called 'packed BCD'), for space saving.

Several CPU architectures support arithmetic operations on BCD values - although some not fully: I was working with a machine that had hardware (well, actually it was microcoded) add, subtract, and multiply of BCD. Dynamic analysis of real-life Cobol applications showed that BCD division was almost never done. The cost of implementing BCD divide in hardware was too high to justify it, so the instruction code was defined, causing an "Unimplemented instruction code" interrupt, and an interrupt handler performed the operation in software. (Very slow, but noone ever complained about that since 'nobody' ever did BCD divide.)

If your CPU does not provide BCD instructions, but you want to offer a Cobol compiler to your customers, you must implement BCD in software, for two reasons: Numeric data types are defined by the number of decimal digits, and that is exact, not "at least". If you have defined a 6-digit decimal, attempting to store a value of one million shall cause an exception. Second: You shall have an exact representation of fractional values - adding five times 20 cents shall give exactly one dollar.

I would not be suprised if those values you have come across is internally stored as BCD, being converted to binary int only because you insisted on it, requesting an int format. It is like converting BCD digits to ASCII digits - it is for presentation, not for processing. If your programming language doesn't support BCD, that binary format is what makes presentation easiest. If you need to do heavy processing, you can write the conversion to linear seconds in a single line numeric expression.
GeneralRe: So there I was... Pin
englebart5-Oct-17 2:18
professionalenglebart5-Oct-17 2:18 
GeneralThat story about Santa Claus... Pin
RogelioP / EX DE,HL4-Oct-17 6:30
professionalRogelioP / EX DE,HL4-Oct-17 6:30 
GeneralRe: That story about Santa Claus... Pin
Mark Parity4-Oct-17 6:43
Mark Parity4-Oct-17 6:43 
GeneralRe: That story about Santa Claus... Pin
Member 133955144-Oct-17 21:17
Member 133955144-Oct-17 21:17 
GeneralRe: That story about Santa Claus... Pin
kalberts5-Oct-17 0:19
kalberts5-Oct-17 0:19 
GeneralThought of the Day Pin
OriginalGriff4-Oct-17 5:05
mveOriginalGriff4-Oct-17 5:05 
GeneralRe: Thought of the Day Pin
Ravi Bhavnani4-Oct-17 5:06
professionalRavi Bhavnani4-Oct-17 5:06 
GeneralRe: Thought of the Day Pin
jeron14-Oct-17 5:26
jeron14-Oct-17 5:26 
GeneralRe: Thought of the Day Pin
Ravi Bhavnani4-Oct-17 7:05
professionalRavi Bhavnani4-Oct-17 7:05 
GeneralRe: Thought of the Day Pin
jeron14-Oct-17 7:29
jeron14-Oct-17 7:29 
GeneralRe: Thought of the Day Pin
Ravi Bhavnani4-Oct-17 8:53
professionalRavi Bhavnani4-Oct-17 8:53 
GeneralRe: Thought of the Day Pin
jeron14-Oct-17 9:21
jeron14-Oct-17 9:21 
AnswerRe: Thought of the Day Pin
megaadam4-Oct-17 5:11
professionalmegaadam4-Oct-17 5:11 
GeneralRe: Thought of the Day Pin
R. Giskard Reventlov4-Oct-17 5:15
R. Giskard Reventlov4-Oct-17 5:15 
GeneralRe: Thought of the Day Pin
OriginalGriff4-Oct-17 5:26
mveOriginalGriff4-Oct-17 5:26 
GeneralRe: Thought of the Day Pin
R. Giskard Reventlov4-Oct-17 5:40
R. Giskard Reventlov4-Oct-17 5:40 
GeneralRe: Thought of the Day Pin
Rajesh R Subramanian4-Oct-17 19:37
professionalRajesh R Subramanian4-Oct-17 19:37 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.